I have a list of Products
, each belonging to a different Distributor
.
I need to display a form for each of those products and their corresponding distributor. I can do so with this code:
form_products = ProductFormSet(
queryset = Product.objects.filter(product__id=product_id)
)
The problem is that I need to display the form with the product belonging to a particular Distributor
named "FirstDistributor" first in the page.
I tried to do so with the following code using the | operator between the querysets:
form_products = ProductFormSet(
queryset=(
Product.objects.filter(
product__id=product_id,
distributor__name='FirstDistributor') |
Product.objects.filter(
product__id=product_id
).exclude(distributor__name='FirstDistributor')
)
)
But the forms are still displayed in the same order. How can I concatenate those two querysets into one, while keeping the same order?
q1 = Product.objects.filter(product__id=product_id,
distributor__name='FirstDistributor')
and
q2 = Product.objects.filter(product__id=product_id
).exclude(distributor__name='FirstDistributor')
Thanks!