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 -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -