Commit 80016ee6 by Florian Apolloner

Fixed #176 -- Disallow multiple TaggableManagers with the same through model.

parent 1f4ffa62
......@@ -130,10 +130,12 @@ class TaggableManager(RelatedField, Field):
tagged_items = GenericRelation(self.through)
tagged_items.contribute_to_class(cls, 'tagged_items')
for rel in cls._meta.local_many_to_many:
if isinstance(rel, TaggableManager) and rel.use_gfk and rel != self:
raise ValueError('You can only have one TaggableManager per model'
' using generic relations.')
for rel in cls._meta.local_many_to_many:
if rel == self or not isinstance(rel, TaggableManager):
continue
if rel.through == self.through:
raise ValueError('You can\'t have two TaggableManagers with the'
' same through model.')
def save_form_data(self, instance, value):
getattr(instance, self.name).set(*value)
......
......@@ -21,6 +21,14 @@ class MultipleTags(models.Model):
tags1 = TaggableManager(through=Through1, related_name='tags1')
tags2 = TaggableManager(through=Through2, related_name='tags2')
# Ensure that two TaggableManagers with GFK via different through models are allowed.
class ThroughGFK(GenericTaggedItemBase):
tag = models.ForeignKey(Tag, related_name='tagged_items')
class MultipleTagsGFK(models.Model):
tags1 = TaggableManager(related_name='tagsgfk1')
tags2 = TaggableManager(through=ThroughGFK, related_name='tagsgfk2')
@python_2_unicode_compatible
class Food(models.Model):
......
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