How do I include strings from a non-tag field as tags using django-tagging?
In Django, using the django-tagging app, I want to make it so that items included in a field that isn't a TagField (e.g., authors
, in this example) are added to the list of explicitly provided tags when the object is saved.
class Publication(models.Model):
title = models.CharField(max_length=200)
authors = models.CharField(max_length=200)
tags = TagField()
If the authors that are submitted are "John, Bob, Mary" and the tags "cooking, fun" are submitted, how do I get the final tag set to be "John, Bob, Mary, cooking, fun"?
I tried adding a custom save function to the Publication class, but I don't think I got it right.
def save(self, *args, **kwargs):
super(Publication, self).save(*args, **kwargs)
for author in parse_tag_input(self.authors):
Tag.objects.add_tag(self, slugify(author))
super(Publication, self).sa开发者_开发百科ve(*args, **kwargs)
How do I add in those extra tags?
I think second super(...).save(...) is wrong. You doing all right according docs
精彩评论