Skip to content

Commit

Permalink
Allow overriding user's attribute names for related managers
Browse files Browse the repository at this point in the history
  • Loading branch information
macro1 committed Oct 8, 2014
1 parent 436edba commit 795f813
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tip (unreleased)
----------------
- Removed some incompatibilities with non-default admin sites (gh-92)
- Fixed error caused by ``HistoryRequestMiddleware`` during anonymous requests (gh-115 fixes gh-114)
- Added workaround for clashing related historical accessors on User (gh-121)

1.5.0 (2014-08-17)
------------------
Expand Down
7 changes: 5 additions & 2 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def python_2_unicode_compatible(klass):
class HistoricalRecords(object):
thread = threading.local()

def __init__(self, verbose_name=None, bases=(models.Model,)):
def __init__(self, verbose_name=None, bases=(models.Model,),
user_related_name=None):
self.user_set_verbose_name = verbose_name
self.user_related_name = user_related_name
try:
if isinstance(bases, basestring):
raise TypeError
Expand Down Expand Up @@ -178,7 +180,8 @@ def get_instance(self):
return {
'history_id': models.AutoField(primary_key=True),
'history_date': models.DateTimeField(),
'history_user': models.ForeignKey(user_model, null=True),
'history_user': models.ForeignKey(
user_model, null=True, related_name=self.user_related_name),
'history_type': models.CharField(max_length=1, choices=(
('+', 'Created'),
('~', 'Changed'),
Expand Down
2 changes: 1 addition & 1 deletion simple_history/tests/external/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Poll(models.Model):
This model intentionally conflicts with the 'Polls' model in 'tests.models'.
"""
history = HistoricalRecords()
history = HistoricalRecords(user_related_name='+')

class Meta:
app_label = 'external'

0 comments on commit 795f813

Please sign in to comment.