![](/img/trans.png)
[英]Getting all the tags associated with the parent object using django-taggit
[英]Getting a specific tag object using django-taggit
我正在使用django-taggit管理我的應用程序中的標簽。 我能夠像這樣拉出標記的項目:
photos = Photo.objects.filter(
Q(status = 1) & Q(tags__id__in=[id])
).order_by('-position')
我想得到的是當前的標簽名稱。 我怎樣才能做到這一點?
您正在傳遞tags__id__in
,這意味着您知道標簽ID? 所以直接得到它們。
tags = Tags.objects.filter(id__in=[ids])
for tag in tags:
print tag.name
或者使用您提到的查詢(我從您的查詢中排除tags__id__in
)
photos = Photo.objects.filter(status=1).order_by('-position')
for photo in photos:
tags = photo.tags.all()
for tag in tags:
print tag.name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.