I have two Model Product and ProductBundle. ProductBundle have a foreign key of Product Model. How can I access a list of all product with there productbundle.
c
You should change the related_name
of product
inside ProductBundle
to something like bundles
and then you can go product.bundles.all()
to access all ProductBundle
related to a Product
edit to filter all products if they have a ProductBundle
assuming you are using bundles
as related_name
:
Product.objects.filter(bundles__isnull=False).distinct()