| 91 | def is_equal(self, other, excludes = None): |
| 92 | """ |
| 93 | Returns a boolean if the two instances of a model are equal. |
| 94 | If ``excludes`` is specified, all fields with the names given in |
| 95 | ``excludes`` will not be considered in the comparison. |
| 96 | If ``excludes`` is not specified, it will default to be the |
| 97 | primary key. |
| 98 | """ |
| 99 | if self is other: return True |
| 100 | if type(self) != type(other): return False |
| 101 | |
| 102 | # if pk happens to be a list of fields, |
| 103 | # we should deal with that |
| 104 | if excludes is None: |
| 105 | if isinstance(type(self)._meta.pk, Field): |
| 106 | excludes = [type(self)._meta.pk.attname] |
| 107 | else: |
| 108 | excludes = [field.attname for field in type(self)._meta.pk] |
| 109 | |
| 110 | field_names = [field.attname for field in type(self)._meta.fields |
| 111 | if field.attname not in excludes ] |
| 112 | print field_names |
| 113 | for field_name in field_names: |
| 114 | if getattr(self, field.name) != getattr(other, field.name): |
| 115 | return False |
| 116 | return True |
| 117 | |
| 118 | |