S
S
Sama Samsonov2017-01-04 11:55:39
Django
Sama Samsonov, 2017-01-04 11:55:39

How to implement this request in django?

Select * from polls_answer where votes = 1 and is_active = 1
How to implement this request in a view?
By means of django. Are there built-in functions.
And how to directly write sql queries in django?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tash1moto, 2017-01-04
@samuser

clean queries should be written as an argument to the raw method:
but it's better not to do so.

for p in Polls_answers.objects.raw('Select * from polls_answer where votes = 1 and is_active = 1'):
...     print(p)

built-in function.
Polls_answers.objects.filter(votes=1,is_active = 1)

H
Hikmat Abdunabiev, 2017-01-04
@Khikmat

djbook.ru/rel1.9/topics/db/queries.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question