Skip to content

Commit

Permalink
Added dictionary comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
macro1 committed Dec 2, 2015
1 parent 81ccf5f commit a3da24c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions simple_history/management/commands/_populate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def bulk_history_create(model, history_model):
history_model(
history_date=getattr(instance, '_history_date', now()),
history_user=getattr(instance, '_history_user', None),
**dict((field.attname, getattr(instance, field.attname))
for field in instance._meta.fields)
**{
field.attname: getattr(instance, field.attname)
for field in instance._meta.fields
}
) for instance in model.objects.all()]
history_model.objects.bulk_create(historical_instances)
6 changes: 4 additions & 2 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ def revert_url(self):
[getattr(self, opts.pk.attname), self.history_id])

def get_instance(self):
return model(**dict([(field.attname, getattr(self, field.attname))
for field in fields.values()]))
return model(**{
field.attname: getattr(self, field.attname)
for field in fields.values()
})

return {
'history_id': models.AutoField(primary_key=True),
Expand Down

0 comments on commit a3da24c

Please sign in to comment.