Django wildcard (Objects.filter)

Is there a wildcard in Django for use in Objects.filter?

For example, is there a character equivalent to this:

Prices.objects.filter(a = example1
                     ,b = example2
                    #,c = example3
)

i.e. instead of commenting on c, can I put c = WILDCARD or c = * ... you get jist. Thanks.

EDIT: Just as if you have a large list of attributes that can be found, and you only want to select a few favorites, you definitely will not have many functions that perform these specific searches. I need some kind of character that Django says, and then SQL "this field does not matter, I want everything here" ... not including the field (as in the example) just creates shedload functions.

+3
source share
2 answers

, , , :

filters = {"a": "example1", "b": "example2", "c": "example3" }
prices = Prices.objects.filter(**filters)

dict , / . ** . :

http://www.nomadjourney.com/2009/04/dynamic-django-queries-with-kwargs/

+7

contains icontains,

:

Foo.objects.filter(name__icontains = 'hello') #fetches all whose name field contains 'hello'
+8

Source: https://habr.com/ru/post/1715899/


All Articles