Skip to content

Commit

Permalink
Merge e8ba322 into 0001c47
Browse files Browse the repository at this point in the history
  • Loading branch information
macro1 committed Oct 2, 2014
2 parents 0001c47 + e8ba322 commit cb48ca2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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
14 changes: 14 additions & 0 deletions simple_history/tests/external/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
from __future__ import unicode_literals

from django.db import models
from simple_history.models import HistoricalRecords

from .model2 import ExternalModel2
from .model4 import ExternalModel4


class Poll(models.Model):
"""Test model for same-named historical models
This model intentionally conflicts with the 'Polls' model in 'tests.models'.
"""
history = HistoricalRecords(user_related_name='+')

class Meta:
app_label = 'external'

0 comments on commit cb48ca2

Please sign in to comment.