I have 3 models Product,Photo,ProductLikeDislike. I am left joining all the
three. For that I wrote this query:

x=Product.objects.values_list('name','photo','productlikedislike')


Through this I am getting correct left join I printed and checked like this:

*Note*: olx is the name of my Django app.

print(x.query)

SELECT "olx_product"."name", "olx_photo"."id", "olx_productlikedislike"."id"
 FROM "olx_product" LEFT OUTER JOIN "olx_photo" ON ("olx_product"."id"
= "olx_photo"."reference_id_id") LEFT OUTER JOIN
"olx_productlikedislike" ON ("olx_product"."id" =
"olx_productlikedislike"."product_id_id") ORDER BY
"olx_product"."created" DESC

Now I want to add extra and condition along with ON statement like this:

ON ("olx_product"."id" =
    "olx_productlikedislike"."product_id_id"and
"olx_productlikedislike"."product_liked_by_id"=2)

So for this somebody suggested me that use Django's FilteredRelation. I
used but it is not adding extra and condition along with ON

I used FilteredRelation like this:

x=Product.objects.annotate(
productlikedislike_product_liked_by_id=FilteredRelation('productlikedislike',
condition=Q(productlikedislike__product_liked_by_id=2))).values_list('name','photo','productlikedislike')

but getting the same sql query no extra and condition. I am using Django
2.1.5

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABCRpYO4efTqkUn7OK8_yLU12M%2B%2B_ibgiZwE6feV-g0LNK9cxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to