gpt4 book ai didi

django-taggit 深层关系查询

转载 作者:行者123 更新时间:2023-12-04 21:24:11 27 4
gpt4 key购买 nike

我正在使用 django-taggit 并且在尝试过滤关系时遇到了一个问题。

有以下型号:

class Artist(models.Model):
tags = TaggableManager()


class Gig(models.Model):
artist = models.ManyToManyField(Artist)

我想要实现的是让所有演出的艺术家都有一个特定的标签。

我认为这会很容易并热切地写道:
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

最佳答案

我设法通过注释掉 来修复它TaggableManager.extra_filters() 在管理.py。

持保留态度,因为我不知道这样做可能会破坏什么。

关于django-taggit 深层关系查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6560287/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com