C
C
Cyber_bober2016-03-13 17:12:05
Django
Cyber_bober, 2016-03-13 17:12:05

How to convert such request to ORM?

Hello, I want to make such selections

SELECT * FROM posts WHERE category.id = id AND tag.id IN (1, 2, 3)

How to do it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rostislav Grigoriev, 2016-03-13
@Cyber_bober

`Post.objects.filter(category=category_id, tag__in=(1, 2, 3))`

S
Sergey Gornostaev, 2016-03-13
@sergey-gornostaev

Engine repair through the exhaust pipe. Models to see. I suspect something like this

Post.objects.filter(category_id=cat_id, tag_id__in=[1, 2, 3])

O
Oscar Django, 2016-03-13
@winordie

Posts.objects.filter(category=category.name, tags__in=(tag1, tag2, tag3))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question