diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2013-09-25 13:47:46 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-09-25 13:47:46 +0100 |
| commit | 05656f2388b1989c9e99e1ff2aae8b2e1c805af2 (patch) | |
| tree | f59f074e2c9f4b91960376678f9973cbe3cc2b62 /django | |
| parent | 9027da65d3590a3bd319490d78c86ef09cd04f9e (diff) | |
Add equality support for Project/ModelState
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/state.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index 0e532d3fdc..25b4b2b102 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -59,6 +59,14 @@ class ProjectState(object): models[(model_state.app_label, model_state.name.lower())] = model_state return cls(models) + def __eq__(self, other): + if set(self.models.keys()) != set(other.models.keys()): + return False + return all(model == other.models[key] for key, model in self.models.items()) + + def __ne__(self, other): + return not (self == other) + class ModelState(object): """ @@ -167,3 +175,16 @@ class ModelState(object): if fname == name: return field raise ValueError("No field called %s on model %s" % (name, self.name)) + + def __eq__(self, other): + return ( + (self.app_label == other.app_label) and + (self.name == other.name) and + (len(self.fields) == len(other.fields)) and + all((k1 == k2 and (f1.deconstruct()[1:] == f2.deconstruct()[1:])) for (k1, f1), (k2, f2) in zip(self.fields, other.fields)) and + (self.options == other.options) and + (self.bases == other.bases) + ) + + def __ne__(self, other): + return not (self == other) |
