Commit aa06730d by Florian Apolloner

Merge branch 'blueyed-deconstruct-keep-non-defaults' into develop

Conflicts:
	taggit/managers.py
parents 5b25238f 8fb7cfaf
......@@ -220,12 +220,14 @@ class TaggableManager(RelatedField, Field):
_related_name_counter = 0
def __init__(self, verbose_name=_("Tags"), help_text=_("A comma-separated list of tags."),
through=None, blank=False, related_name=None, manager=_TaggableManager):
through=None, blank=False, related_name=None, to=None,
manager=_TaggableManager):
Field.__init__(self, verbose_name=verbose_name, help_text=help_text, blank=blank, null=True, serialize=False)
self.through = through or TaggedItem
self.rel = TaggableRel(self, related_name, self.through)
self.swappable = False
self.manager = manager
# NOTE: `to` is ignored, only used via `deconstruct`.
def __get__(self, instance, model):
if instance is not None and instance.pk is None:
......@@ -240,9 +242,17 @@ class TaggableManager(RelatedField, Field):
return manager
def deconstruct(self):
"""
Deconstruct the object, used with migrations.
"""
name, path, args, kwargs = super(TaggableManager, self).deconstruct()
# Remove forced kwargs.
for kwarg in ('serialize', 'null'):
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
return name, path, args, kwargs
def contribute_to_class(self, cls, name):
......
from __future__ import unicode_literals, absolute_import
from unittest import TestCase as UnitTestCase
from unittest import skipIf
import django
from django.conf import settings
......@@ -547,3 +548,12 @@ class TagStringParseTestCase(UnitTestCase):
self.assertEqual(edit_string_for_tags([plain, spaces, comma]), '"com,ma", "spa ces", plain')
self.assertEqual(edit_string_for_tags([plain, comma]), '"com,ma", plain')
self.assertEqual(edit_string_for_tags([comma, spaces]), '"com,ma", "spa ces"')
@skipIf(django.VERSION < (1, 7), "not relevant for Django < 1.7")
class DeconstructTestCase(UnitTestCase):
def test_deconstruct_kwargs_kept(self):
instance = TaggableManager(through=OfficialThroughModel)
name, path, args, kwargs = instance.deconstruct()
new_instance = TaggableManager(*args, **kwargs)
self.assertEqual(instance.rel.through, new_instance.rel.through)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment