python - Django: get subset of a model with at least one related model -
class category(models.model): # fields class product(models.model): category = models.foreignkey(category) # fields
assuming not categories have @ least product,
how can categories have @ least 1 product associated?
is there way django querysets?
you should able filter
on category. want find category
's product isn't null right?:
category.objects.filter(product_set__isnull=false).distinct()
Comments
Post a Comment