5
我正在使用django-taggit,並在嘗試過濾關係時遇到問題。django-taggit深層關係查詢
具有以下型號:
class Artist(models.Model):
tags = TaggableManager()
class Gig(models.Model):
artist = models.ManyToManyField(Artist)
我想實現的是讓所有演出誰的藝術家(S)有一個特定的標籤。
我想這是很容易和熱切寫道:
Gig.objects.filter(artist__tags__name__in=["rock"])
這給了我:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/manager.py", line 141, in filter
return self.get_query_set().filter(*args, **kwargs)
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/query.py", line 550, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/query.py", line 568, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1172, in add_q
can_reuse=used_aliases, force_having=force_having)
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1139, in add_filter
process_extras=False)
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1060, in add_filter
negate=negate, process_extras=process_extras)
File "/home/jonas/.virtualenvs/wsw/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1238, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'tagged_items' into field. Choices are: artist, date, id, location, url
我看到你幾個月前發佈了這個。你解決了嗎? – avatar
對不起,延遲迴復。我從來沒有解決它。我只是轉向django-tagging,這使得這種行爲成爲可能。但是與django-taggit相比,我必須警告你它的API結構。它仍然有一些很好的詳細文檔。 –
謝謝你的回覆! – avatar