Skip to content

Commit

Permalink
add non-abstract parent comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
LegoStormtroopr committed Feb 1, 2016
1 parent 38b3266 commit cf69a69
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions reversion_compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def get_reverse_foreign_key(self):
ids = []
else:
ids = [v.id for v in getattr(obj, str(self.field.related_name)).all()] # is: version.field_dict[field.name]
if ids == [] and any([f.name.endswith('_ptr') for f in obj._meta.fields]):
# this object inherits from a non-abstract class, lets try and get the parent items associated entries
others = self.version.revision.version_set.filter(object_id=self.version.object_id)
for p in others:
p_obj = p.object_version.object
if type(p_obj) != type(obj) and hasattr(p_obj,str(self.field.related_name)):
ids = [v.id for v in getattr(p_obj, str(self.field.related_name)).all()]

else:
return ([], [], [], []) # TODO: refactory that
Expand All @@ -124,7 +131,6 @@ def get_many_to_many(self):
return self.get_many_to_something(ids, related_model)

def get_many_to_something(self, ids, related_model, is_reverse=False):

# get instance of reversion.models.Revision():
# A group of related object versions.
old_revision = self.version.revision
Expand Down Expand Up @@ -166,7 +172,8 @@ def get_many_to_something(self, ids, related_model, is_reverse=False):
if ver.revision.date_created < old_revision.date_created:
true_missing_objects.append(o)
missing_objects = true_missing_objects
deleted = [d for d in reversion.revisions.get_deleted(related_model) if d.revision == old_revision]
deleted = [d for d in reversion.get_deleted(related_model) if d.revision == old_revision]

return versions, missing_objects, missing_ids, deleted

def get_debug(self):
Expand Down

0 comments on commit cf69a69

Please sign in to comment.