Skip to content

Commit

Permalink
Revert "fix model + tests for foreign keys (issue #38)"
Browse files Browse the repository at this point in the history
This reverts commit febf43b.
  • Loading branch information
treyhunner committed May 10, 2013
1 parent cf78b40 commit c9a88d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
16 changes: 3 additions & 13 deletions simple_history/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
from django.db import models
from django.db.models.loading import get_model
from django.conf import settings
from django.contrib import admin
from django.utils import importlib
Expand Down Expand Up @@ -85,21 +84,10 @@ def copy_fields(self, model):
field.__class__ = models.TextField

if isinstance(field, models.ForeignKey):
rel_model = field.rel.to
field.name = field.get_attname()
if isinstance(field.rel.to, basestring):
rel_model = get_model(*field.rel.to.split('.',1))

if isinstance(rel_model._meta.pk, models.fields.AutoField):
field.__class__ = models.IntegerField
else:
rel_field = rel_model._meta.pk
field.__class__ = type(rel_field)
field.max_length = rel_field.max_length
field.__class__ = models.IntegerField
#ughhhh. open to suggestions here
field.rel = None
field.related = None
field.related_name = None
field.related_query_name = None
field.null = True
field.blank = True
Expand All @@ -118,6 +106,8 @@ def copy_fields(self, model):
field._unique = False
field.db_index = True
field.serialize = True
if fk:
field.name = field.name + "_id"
fields[field.name] = field

return fields
Expand Down
4 changes: 2 additions & 2 deletions simple_history/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def test_non_default_primary_key_save(self):
library.save()
library.book = None
library.save()
self.assertEqual([l.book_id for l in library.history.all()],
[None, book2.isbn, book1.isbn])
self.assertEqual([l.book for l in library.history.all()],
[None, book2, book1])

def test_string_defined_foreign_key_save(self):
library1 = Library.objects.create()
Expand Down

0 comments on commit c9a88d0

Please sign in to comment.