私のmodels.py:。ジャンゴ:Q(...)&Q(...)は、フィルタ(...)と同じではありませんフィルタリング(...)
class Words(models.Model):
sentence = models.ForeignKey(Sentences, related_name='sentence_having_this_word')
wordtext = models.CharField(max_length=250) # NOT UNIQUE. words written similarly can appear, as long as the sentences are different.
class Sentences(BaseModel):
pass
レッツのは、私が2つの文を持っていると言う: I see a tree and a house.
とthe tree is in front of the house.
Words
が含まれています:'I'
、'see'
、'a'
、'tree'
、'and'
、'a'
、'house'
(ForeignKeyの持つすべてのこれらの単語の最初の文に)、'the'
、を,'is'
,'in'
,'front'
,'of'
,'the'
,'house'
(これらの語は、第2文にFKを付ける)。
私はこれら2つの単語が同じように書かれた文章を探しています。'tree'
と'house'
です。
私はない:
Sentences.objects.filter(Q(sentence_having_this_word__wordtext='tree')&Q(sentence_having_this_word__wordtext='house')).all()
==> []。結果ん
が、私がしなければいいえ:私はQ(...)&Q(...)
とfilter(...).filter(...)
は同じものだと思っていた I see a tree and a house.
、the tree is in front of the house.
: Sentences.objects.filter(sentence_having_this_word__wordtext='tree').filter(sentence_having_this_word__wordtext='house')).all()
は==>私は期待どおりの結果を持っていますか?
EDIT&
オペレーターは動作しません。それが働いているand
で
、...ドキュメント内
、それは言及していないが(https://docs.djangoproject.com/en/1.7/topics/db/queries/#complex-lookups-with-q-objects)
これを書いて時間を割いてくれてありがとう。それは今非常に明確です! – ThePhi