DJango ORM - analogue for LEFT JOIN query

25 Views Asked by At

models.py

class Products(models.Model):
      name = models.CharField()
      price = models.IntegerField()

class Products_Images(models.Model):
      products  = models.ForeignKey(Products)
      image = models.ImageField()
      name = models.CharField()

I need to get PRODUCTS and only ONE or NO image for each product.

Like this:

SELECT Products.*,Products_Images.* FROM Products
LEFT JOIN Products_Images on Products.id=Products_Images.product_id AND Products_Images.name LIKE '%pizza%'
WHERE Products.price >= 50
0

There are 0 best solutions below