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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -