D
D
Djangist2020-05-12 18:23:10
PostgreSQL
Djangist, 2020-05-12 18:23:10

Filtering to prioritize one category over another?

There are 2 tables - Posts and Categories. There is a many to many relationship between them. You need to get 3 Posts, 4 categories are involved in the filtering, but among the sample of these three Posts, at least one Post must correspond to the priority category. That is:
Category-0 (priority), Category-1, Category-2, Category-3 participate in the filtering.
As a result, you need to get at least 1 Post that has a connection with Category-0 and 2 more random Posts that match the filtering conditions.
How to determine the priority to the category I need?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Shatalov, 2020-05-12
@netpastor

Instead of complex filters, I would make one queriset for the priority category and one more for non-priority ones and use union

S
siarheisiarhei, 2020-05-16
@siarheisiarhei

objects.filter = .........?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question