简体   繁体   中英

Django-Taggit validate newly added tags before save

This is how my models look like. I was not able to do the validation by overriding the save method of either of the models.

class NotificationListTag(TaggedItemBase):
    content_object = models.ForeignKey('Mailer')


class Mailer(models.Model):

    from_email = models.CharField(max_length=255)
    to_emails = TaggableManager(
        through=NotificationListTag,
        blank=True,
        verbose_name='To Emails',
        help_text='Space separated email ID'
    )

How do I validate each of the newly added tags before it gets saved. Did I miss something out.

I ended up creating a custom API for the tagging autocomplete suggestions, that only suggests valid names.

You can override the the tagit.js call wagtail makes by default, to pass your custom autocomplete URL to it. In this way, you don't have to do validation after the user has entered a value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM