E
E
Elvinchik2022-01-11 20:21:24
Django
Elvinchik, 2022-01-11 20:21:24

How to display the entire table from the database if None came from the form?

For example, there is this code:

qs = request.GET.post("q") # И значение переменной None

model = Model.objects.filter(name=qs)

But it won't get me anything. How to make it display everything from the table? Is there some method in Django?
By type: model = Model.objects.filter(name=all()).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-01-11
@bacon

ifand Model.objects.all()
Let's play guessing games, since in the comments we found out that there are a lot of fields and "shit code", then

model = Model.objects.all()
for field in ['field1', 'field2', 'field3']:
    if value := request.GET.get(field):
        model = model.filter(**{field: value})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question