Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 3, 2023
1 parent 2f759b2 commit eb732e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,12 @@ def _get_through_field_name(self, through_table_fields, model):
"""
foreign_keys = filter(
lambda model_field: isinstance(model_field, models.ForeignKey),
through_table_fields
through_table_fields,
)
for field in foreign_keys:
if field.related_model == model:
return field.name


def create_historical_record_m2ms(self, history_instance, instance):
for field in history_instance._history_m2m_fields:
m2m_history_model = self.m2m_models[field]
Expand All @@ -684,8 +683,7 @@ def create_historical_record_m2ms(self, history_instance, instance):

# find the name of the field in custom or default through table
through_field_name = self._get_through_field_name(
through_model._meta.fields,
original_instance._meta.model
through_model._meta.fields, original_instance._meta.model
)

rows = through_model.objects.filter(**{through_field_name: instance})
Expand Down
5 changes: 3 additions & 2 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class Tag(models.Model):


class PollTags(models.Model):
poll = models.ForeignKey("PollParentWithManyToManyCustomThrough", on_delete=models.CASCADE)
poll = models.ForeignKey(
"PollParentWithManyToManyCustomThrough", on_delete=models.CASCADE
)
tag = models.ForeignKey(Tag, on_delete=models.CASCADE)


Expand Down Expand Up @@ -306,7 +308,6 @@ def verbose_str(self):
register(Voter, records_class=HistoricalRecordsVerbose)



class Place(models.Model):
name = models.CharField(max_length=100)

Expand Down

0 comments on commit eb732e1

Please sign in to comment.