So I have this simple django Model called Post with some date about the user who posted a message and a message it self.
class Post(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name="posts",null=False)
text = models.CharField(max_length=400)
date_created = models.DateField(auto_now_add=True,auto_now = False)
date_modified = models.DateField(auto_now=True)
tags = models.ManyToManyField(Tag,related_name="posts")
And I need to implement a tagging system like twitter has it. So when Post gets saved I need to capture the tags from the text field and place them somehow in a many2many relation so that I am able to do stuff like 'tag.posts' to get all the Posts with this tag or the other way around. I have the algorithm to capture the tags but I am stuck on implementing this automatic way of creating a Tag Object when creating/editing/saving a Post. I already tried to override the save Method, create a Manager or listen to the post_save signal but it didn't work.
How is this implemented the best? Thank you in advance!
我的建议是捕获pre_save信号并创建不存在的标签。
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.