Skip to content

Commit

Permalink
Fetch OneToOne field foreign_key from the objects attribute instead o…
Browse files Browse the repository at this point in the history
…f all()

A OneToOne field does not have a all() function, which leads to an exception when
all() is called.
  • Loading branch information
Frank Wickström committed Jun 18, 2015
1 parent 1fe9d88 commit 9adf038
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion reversion_compare/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
except ImportError: # Django < 1.7
from django.contrib.admin.util import unquote, quote
from django.core.urlresolvers import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.http import Http404
from django.contrib import admin
Expand Down Expand Up @@ -108,7 +109,14 @@ def get_reverse_foreign_key(self):
obj = self.version.object_version.object
# self = getattr(obj, self.field.related_name) #self.field.field_name
if self.has_int_pk and self.field.related_name and hasattr(obj, self.field.related_name):
ids = [v.id for v in getattr(obj, str(self.field.related_name)).all()] # is: version.field_dict[field.name]
if isinstance(self.field, models.fields.related.OneToOneRel):
try:
ids = [getattr(obj, str(self.field.related_name)).pk]
except ObjectDoesNotExist:
ids = []
else:
ids = [v.id for v in getattr(obj, str(self.field.related_name)).all()] # is: version.field_dict[field.name]

else:
return ([], [], [], []) # TODO: refactory that

Expand Down

0 comments on commit 9adf038

Please sign in to comment.