Skip to content

Commit

Permalink
Make FIELDS_TO_CHECK uses casual field name in case of ForeignKey ins…
Browse files Browse the repository at this point in the history
…tead of fieldname_id pattern which is confusing
  • Loading branch information
mounirmesselmeni committed Oct 11, 2018
1 parent 7c8d2fd commit 8c7e04b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/dirtyfields/dirtyfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _as_dict(self, check_relationship, include_primary_key=True):
deferred_fields = self.get_deferred_fields()

for field in self._meta.fields:
if self.FIELDS_TO_CHECK and (field.get_attname() not in self.FIELDS_TO_CHECK):
if self.FIELDS_TO_CHECK and (field.name not in self.FIELDS_TO_CHECK):
continue

if field.primary_key and not include_primary_key:
Expand Down Expand Up @@ -138,8 +138,7 @@ def reset_state(sender, instance, **kwargs):
if update_fields:
for field_name in update_fields:
field = sender._meta.get_field(field_name)
if not FIELDS_TO_CHECK or \
(field.get_attname() in FIELDS_TO_CHECK):
if not FIELDS_TO_CHECK or (field.name in FIELDS_TO_CHECK):

if field.get_attname() in instance.get_deferred_fields():
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TestModelWithSpecifiedFieldsAndForeignKey(DirtyFieldsMixin, models.Model):
boolean1 = models.BooleanField(default=True)
boolean2 = models.BooleanField(default=True)
fk_field = models.OneToOneField(TestModel, null=True)
FIELDS_TO_CHECK = ['fk_field_id']
FIELDS_TO_CHECK = ['fk_field']


class TestModelWithM2MAndSpecifiedFields(DirtyFieldsMixin, models.Model):
Expand Down

0 comments on commit 8c7e04b

Please sign in to comment.