class Category(models.Model):
# fields
class Product(models.Model):
category = models.ForeignKey(Category)
# fields
Assuming that not all the categories have at least a product,
how i can get all the categories that have at least one product associated?
Is there a way to do this with Django querysets?
You should be able to filter
on the category. You want to find the Category
's where the product isn't null right?:
Category.objects.filter(product_set__isnull=False).distinct()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With