和使用相同关键字的条件Django查询 [英] And Condition Django Query Using Same Keyword
问题描述
我似乎找不到这个语法,虽然我确定它很容易获得 - 我想我没有使用正确的语言来搜索。我已经尝试过的是:
pubs_for_tags = Publication.objects.filter(tags__title__istartswith = q,tags__title__istartswith = q2)
但这给我一个错误关键字参数重复。我也尝试了一些这样的变化,但迄今没有任何工作。有人可以用这个正确的语法启发我吗?
pubs_for_tags = Publication.objects.filter(tags__title__istartswith = q).filter(tags__title__istartswith = q2)
或
pubs_for_tags = Publication.objects.filter(Q(tags__title__istartswith = q),Q(tags__title__istartswith = q2))
I have a Django application with a Publication model and a Tag model. Each publication has one or more Tags associated with it. I want to query the database with a set of two Tags and have returned only publications that have BOTH of those tags.
I cannot seem to find the syntax for this although I am certain it is readily available - I suppose I am not using the correct language to search. What I have tried already is:
pubs_for_tags = Publication.objects.filter(tags__title__istartswith=q, tags__title__istartswith=q2)
But this gives me an error "keyword argument repeated". I've also tried some variations of this, but nothing has worked so far. Can someone enlighten me on the correct syntax for this?
pubs_for_tags = Publication.objects.filter(tags__title__istartswith=q).filter( tags__title__istartswith=q2)
or
pubs_for_tags = Publication.objects.filter(Q(tags__title__istartswith=q), Q( tags__title__istartswith=q2))
这篇关于和使用相同关键字的条件Django查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!