'How to filter in a table column contains list in django
I have a table column A=['1','2','3'] and I want filter from the table if the filter value is exist in the list.
eg:
id='1'
Models.objects.filter(A=id)
Solution 1:[1]
object = Models.objects.filter(A__contains=id)
Solution 2:[2]
Supposing the name of the model is Foo, in order to find the object with the column A=id, you would do:
object = Foo.objects.filter(A=id)
This has the same effect as:
object = Foo.objects.filter(A__exact=id)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Fatih Y?ld?z |