Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditions addition to insert_row #1359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ def create_historical_record_m2ms(self, history_instance, instance):
m2m_history_model = self.m2m_models[field]
original_instance = history_instance.instance
through_model = getattr(original_instance, field.name).through
through_model_field_names = [f.name for f in through_model._meta.fields]
through_model_fk_field_names = [
f.name for f in through_model._meta.fields if isinstance(f, ForeignKey)
]
Expand All @@ -700,8 +699,14 @@ def create_historical_record_m2ms(self, history_instance, instance):
for row in rows:
insert_row = {"history": history_instance}

for field_name in through_model_field_names:
insert_row[field_name] = getattr(row, field_name)
for through_model_field in through_model._meta.fields:
# Remove any excluded kwargs for the field.
if through_model_field.name not in self.field_excluded_kwargs(
field
):
insert_row[through_model_field.name] = getattr(
row, through_model_field.name
)
insert_rows.append(m2m_history_model(**insert_row))

pre_create_historical_m2m_records.send(
Expand Down