M
M
Michael2017-08-08 19:17:27
PostgreSQL
Michael, 2017-08-08 19:17:27

How to do a search in django?

for example, in the database there is a field that has a granite value in the form of
"one two three"; "one"; "two"; "three"; "two three"; "one three"; "one two"; "three two one" i.e. in any combination and separated by a space.
I receive data from the client in the form "one two three" or [one, two, three]
I need to exclude all records where the data is mentioned at least once.
I do

coun_id = request.GET.get('coun', None)
            bl = request.GET.getlist('bl[]', None)
            
            if coun_id and bl:
                coun = Count.objects.get(id=coun_id)
                b = ' '.join(bl)
             
                snippets = Model.objects.filter(test=count) \
                                         .exclude(Q(list__in=bl) | \
                                         Q(list__istartswith=b) | \
                                         Q(list__endswith=b) | \
                                         Q(list__icontains=b) | \
                                         Q(list__in=b))[:300]

But all the same, options slip when the words in the table are in a different order than they came from the client.
How to solve this problem?
Postgres base

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question