如何找到遵循主题标签的人的否-Django
我已经使用 django-taggit 在我的帖子中添加标签项目。 我的帖子模型架构就是这样:
class Feed(models.Model):
user = models.ForeignKey(User,
on_delete=models.CASCADE,related_name='feedposts')
publish =models.DateTimeField(default = timezone.now)
created = models.DateTimeField(auto_now_add=True)
***
tags = TaggableManager()
为了使用户遵循主题标签。我已经在用户模型架构中添加了此字段,看起来像这样。
class Profile(models.Model):
****
following_tags = TaggableManager()
然后,如果用户遵循特定标签,我在列出的字段中添加该特定标签。
现在,我们可以根据用户遵循的主题标签获取提要。但是现在,我想找出遵循特定主题标签的人总数,这是我无法做的。 另外,请告诉我是否还有其他任何实现方法可以使用Django-Taggit来实现此功能,因为它可以轻松使用它,而只需制作一个简单的consthtags表,就像下面的那样,
class FollowedHashtags(models.Model):
name = models.CharField(unique = True)
user = models.ManyTOManyField(User)
我们可以让没有人遵循标签的人:
hashtag = FollowedHashtags.objects.get(id=1)
nooffollowers = hashtag.user.count()
我尝试了一些过滤查询,但还没有成功。因此,如果知道任何其他实现或方式,否则您可以正确地建议我。我会非常感谢你。
I have used Django-Taggit in the posts to add tagging in my project.
My post model schema is like this :
class Feed(models.Model):
user = models.ForeignKey(User,
on_delete=models.CASCADE,related_name='feedposts')
publish =models.DateTimeField(default = timezone.now)
created = models.DateTimeField(auto_now_add=True)
***
tags = TaggableManager()
In order to make user follow the hashtags. I have added this field in the User Model Schema which looks like this.
class Profile(models.Model):
****
following_tags = TaggableManager()
Then if the user follows the particular tag, I add that particular tag in the listed field.
Now we can get the feed according to the hashtags user is following. But now I want to find out the total number of people following a particular hashtag and this is something I am not able to do.
Also, Please tell me if there is any other implementation from which I can achieve this feature using django-taggit since it is easy without using it by just making a simple table of FollowedHashtags like below
class FollowedHashtags(models.Model):
name = models.CharField(unique = True)
user = models.ManyTOManyField(User)
We can get the no of people following the Hashtags:
hashtag = FollowedHashtags.objects.get(id=1)
nooffollowers = hashtag.user.count()
I have tried some filtering queries but no success yet. So if know any other implementation or way or you could suggest me the right way. I would be highly thankful to you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这会为你做
I think this will do for you