Commit 7fe3a0b9 by Gert Van Gool

Added support for blank=True

parent 73c6fad4
...@@ -36,12 +36,13 @@ class TaggableRel(ManyToManyRel): ...@@ -36,12 +36,13 @@ class TaggableRel(ManyToManyRel):
class TaggableManager(RelatedField): class TaggableManager(RelatedField):
def __init__(self, verbose_name=_("Tags"), help_text=None, through=None): def __init__(self, verbose_name=_("Tags"), help_text=None, through=None, blank=False):
self.use_gfk = through is None or issubclass(through, GenericTaggedItemBase) self.use_gfk = through is None or issubclass(through, GenericTaggedItemBase)
self.through = through or TaggedItem self.through = through or TaggedItem
self.rel = TaggableRel(to=self.through._meta.get_field("tag").rel.to) self.rel = TaggableRel(to=self.through._meta.get_field("tag").rel.to)
self.verbose_name = verbose_name self.verbose_name = verbose_name
self.help_text = help_text or _("A comma-separated list of tags.") self.help_text = help_text or _("A comma-separated list of tags.")
self.blank = blank
self.editable = True self.editable = True
self.unique = False self.unique = False
self.creates_table = False self.creates_table = False
...@@ -77,6 +78,7 @@ class TaggableManager(RelatedField): ...@@ -77,6 +78,7 @@ class TaggableManager(RelatedField):
defaults = { defaults = {
"label": self.verbose_name, "label": self.verbose_name,
"help_text": self.help_text, "help_text": self.help_text,
"required": not self.blank
} }
defaults.update(kwargs) defaults.update(kwargs)
return form_class(**defaults) return form_class(**defaults)
......
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