Skip to content

Commit

Permalink
Merge 51e7a25 into e9bf1a8
Browse files Browse the repository at this point in the history
  • Loading branch information
macro1 committed Nov 21, 2014
2 parents e9bf1a8 + 51e7a25 commit 51565cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion simple_history/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_queryset(self):
if self.instance is None:
return qs

if isinstance(self.instance._meta.pk, models.OneToOneField):
if isinstance(self.instance._meta.pk, models.ForeignKey):
key_name = self.instance._meta.pk.name + "_id"
else:
key_name = self.instance._meta.pk.name
Expand Down
5 changes: 5 additions & 0 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,8 @@ class SeriesWork(models.Model):

class Meta:
order_with_respect_to = 'series'


class PollInfo(models.Model):
poll = models.ForeignKey(Poll, primary_key=True)
history = HistoricalRecords()
9 changes: 8 additions & 1 deletion simple_history/tests/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Person, FileModel, Document, Book, HistoricalPoll, Library, State,
AbstractBase, ConcreteAttr, ConcreteUtil, SelfFK, Temperature, WaterLevel,
ExternalModel1, ExternalModel3, UnicodeVerboseName, HistoricalChoice,
HistoricalState, HistoricalCustomFKError, Series, SeriesWork
HistoricalState, HistoricalCustomFKError, Series, SeriesWork, PollInfo
)
from ..external.models import ExternalModel2, ExternalModel4

Expand Down Expand Up @@ -282,6 +282,13 @@ def test_historical_verbose_name_follows_model_verbose_name(self):
self.assertEqual('historical quiet please',
l.history.get()._meta.verbose_name)

def test_foreignkey_primarykey(self):
"""Test saving a tracked model with a `ForeignKey` primary key."""
poll = Poll(pub_date=today)
poll.save()
poll_info = PollInfo(poll=poll)
poll_info.save()


class RegisterTest(TestCase):
def test_register_no_args(self):
Expand Down

0 comments on commit 51565cd

Please sign in to comment.