-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Don't populate excluded fields while populating existing models history #381
Changes from all commits
34f5ef2
01e346d
a8b1b94
c1d3ddc
f3d21d7
5937337
316836b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,10 @@ def create_history_model(self, model, inherited): | |
""" | ||
Creates a historical model to associate with the model provided. | ||
""" | ||
attrs = {'__module__': self.module} | ||
attrs = { | ||
'__module__': self.module, | ||
'_history_excluded_fields': self.excluded_fields | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still don't love adding this on the model itself. Will think about this about and think about any cleaner solutions. Going to be merging some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reference, this is why we can't put |
||
} | ||
|
||
app_module = '%s.models' % model._meta.app_label | ||
|
||
|
@@ -220,10 +223,20 @@ def revert_url(self): | |
) | ||
|
||
def get_instance(self): | ||
return model(**{ | ||
attrs = { | ||
field.attname: getattr(self, field.attname) | ||
for field in fields.values() | ||
}) | ||
} | ||
if self._history_excluded_fields: | ||
excluded_attnames = [ | ||
model._meta.get_field(field).attname | ||
for field in self._history_excluded_fields | ||
] | ||
values = model.objects.filter( | ||
pk=getattr(self, model._meta.pk.attname) | ||
).values(*excluded_attnames).get() | ||
attrs.update(values) | ||
return model(**attrs) | ||
|
||
def get_next_record(self): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,3 +111,12 @@ def test_no_historical(self): | |
stdout=out) | ||
self.assertIn(populate_history.Command.NO_REGISTERED_MODELS, | ||
out.getvalue()) | ||
|
||
def test_excluded_fields(self): | ||
poll = models.PollWithExcludeFields.objects.create( | ||
question="Will this work?", pub_date=datetime.now()) | ||
models.PollWithExcludeFields.history.all().delete() | ||
management.call_command(self.command_name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
'tests.pollwithexcludefields', auto=True) | ||
initial_history_record = models.PollWithExcludeFields.history.all()[0] | ||
self.assertEqual(initial_history_record.question, poll.question) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to add the PR number to this?
(gh-381)