如何找到遵循主题标签的人的否-Django

发布于 2025-02-14 00:45:16 字数 1140 浏览 4 评论 0原文

我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖凝香 2025-02-21 00:45:16

我认为这会为你做

 FollowedHashtags.objects.filter(id=1).values('user').count()

I think this will do for you

 FollowedHashtags.objects.filter(id=1).values('user').count()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文