Skip to content

Commit

Permalink
Properly serialize through/to in deconstruct.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Aug 10, 2014
1 parent f54b971 commit 5f1ddeb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions taggit/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ def deconstruct(self):
del kwargs[kwarg]
# Add arguments related to relations.
# Ref: https://github.com/alex/django-taggit/issues/206#issuecomment-37578676
kwargs['through'] = self.through
kwargs['to'] = self.through._meta.get_field("tag").rel.to
if isinstance(self.rel.through, six.string_types):
kwargs['through'] = self.rel.through
elif not self.rel.through._meta.auto_created:
kwargs['through'] = "%s.%s" % (self.rel.through._meta.app_label, self.rel.through._meta.object_name)
if isinstance(self.rel.to, six.string_types):
kwargs['to'] = self.rel.to
else:
kwargs['to'] = '%s.%s' % (self.rel.to._meta.app_label, self.rel.to._meta.object_name)
return name, path, args, kwargs

def contribute_to_class(self, cls, name):
Expand All @@ -266,6 +272,10 @@ def contribute_to_class(self, cls, name):
cls._meta.add_field(self)
setattr(cls, name, self)
if not cls._meta.abstract:
if isinstance(self.rel.to, six.string_types):
def resolve_related_class(field, model, cls):
field.rel.to = model
add_lazy_relation(cls, self, self.rel.to, resolve_related_class)
if isinstance(self.through, six.string_types):
def resolve_related_class(field, model, cls):
self.through = model
Expand Down

0 comments on commit 5f1ddeb

Please sign in to comment.