Closed pancakeDevelopment closed 1 year ago
Yes! So like you said, what you need to do is something like Tag.objects.create(...)
to first create the tags (this is if you are using the base Tag
model). So you can just do from taggit.models import Tag
and go from there.
Now the rest is a bit manual but here's an idea for how I would do this from scratch. Here I'm assuming you add tags to a Post
model, via post.tags
.
Post
s, write a validation that checks that the provided tags all already exist (Tag.objects.filter(name__in=tag_list) == len(tag_list)
, if users are passing in a tag list as strings). If the length is mismatched, that means that in the tag list there is a tag that doesn't exist alreadyTag
s or the like so that you can create tags. Alternatively, programmatically create tags inside of a data migrationYou can also create a special Tag
subclass with some extra validation to ensure that the tag name is correct. What makes sense depends on what you are doing, really.
Hi, is there a way to create indepentend tags like:
Tag.objects.create(name="Tag name", slug="tag-name")
Reason: In my use case are allowed to create tags an users can use the pre-defined tags. So users should not be allowed to create new ones.