Issue
I have two samples in an application built using Django:
class User(models.Model):
email = models.EmailField()
class Product(models.Model):
user = models.ForeignKey(User)
I want to filter out all users who don't have any products in the store.
How do I do this?
Solution
This seems the simplest:
user_ids_with_product = [product.user_id for product
in Product.objects.all()]
Users.objects.exclude(id__in=user_ids_with_product)
Answered By - vinkomlacic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.