class Product(models.Model):
category = models.ForeignKey(Category, related_name="products_category", null=True, on_delete=models.CASCADE)
sku = models.CharField(max_length=200, blank=True, null=True)
class ProductVariants(DateTimeModel):
name = models.CharField(max_length=200, blank=True, null=True)
product = models.ForeignKey(Product, related_name="products_variants", null=True, on_delete=models.CASCADE)
products = Product.objects.select_related('category')
how to get all the parent model objects with their related model's first object in a single query. [0] and first() is not working. how to fetch that?