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

Compatibility patch for Django 1.4 #2

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions simple_history/models.py
Expand Up @@ -145,13 +145,21 @@ def create_historical_record(self, instance, type):
manager = getattr(instance, self.manager_name)
attrs = {}
for field in instance._meta.fields:
attrs[field.attname] = getattr(instance, field.attname)
if isinstance(field, models.ForeignKey):
attrs[field.name] = getattr(instance, field.attname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should attname be name instead here?:

attrs[field.name] = getattr(instance, field.name)

else:
attrs[field.attname] = getattr(instance, field.attname)
manager.create(history_type=type, changed_by=changed_by, **attrs)

class HistoricalObjectDescriptor(object):
def __init__(self, model):
self.model = model

def __get__(self, instance, owner):
values = (getattr(instance, f.attname) for f in self.model._meta.fields)
return self.model(*values)
def _gen():
for field in self.model._meta.fields:
if isinstance(field, models.ForeignKey):
yield getattr(instance, field.name)
else:
yield getattr(instance, field.attname)
return self.model(_gen())