Skip to content

Commit 795f813

Browse files
committed
Allow overriding user's attribute names for related managers
1 parent 436edba commit 795f813

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tip (unreleased)
55
----------------
66
- Removed some incompatibilities with non-default admin sites (gh-92)
77
- Fixed error caused by ``HistoryRequestMiddleware`` during anonymous requests (gh-115 fixes gh-114)
8+
- Added workaround for clashing related historical accessors on User (gh-121)
89

910
1.5.0 (2014-08-17)
1011
------------------

simple_history/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ def python_2_unicode_compatible(klass):
5757
class HistoricalRecords(object):
5858
thread = threading.local()
5959

60-
def __init__(self, verbose_name=None, bases=(models.Model,)):
60+
def __init__(self, verbose_name=None, bases=(models.Model,),
61+
user_related_name=None):
6162
self.user_set_verbose_name = verbose_name
63+
self.user_related_name = user_related_name
6264
try:
6365
if isinstance(bases, basestring):
6466
raise TypeError
@@ -178,7 +180,8 @@ def get_instance(self):
178180
return {
179181
'history_id': models.AutoField(primary_key=True),
180182
'history_date': models.DateTimeField(),
181-
'history_user': models.ForeignKey(user_model, null=True),
183+
'history_user': models.ForeignKey(
184+
user_model, null=True, related_name=self.user_related_name),
182185
'history_type': models.CharField(max_length=1, choices=(
183186
('+', 'Created'),
184187
('~', 'Changed'),

simple_history/tests/external/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Poll(models.Model):
1212
1313
This model intentionally conflicts with the 'Polls' model in 'tests.models'.
1414
"""
15-
history = HistoricalRecords()
15+
history = HistoricalRecords(user_related_name='+')
1616

1717
class Meta:
1818
app_label = 'external'

0 commit comments

Comments
 (0)