I would like to create a model manager for my Purchase model:
class Purchase(models.Model)
number = models.IntegerField
class InventoryLog(models.Model)
purchase = models.ForeignKey(Purchase)
sold_out = models.BooleanField(default=false)
I would like my model manager to return any Purchase
objects that are not related to an InventoryLog
object with a sold_out
value of True
Is there a way to handle this with a queryset, Q object or F object, or will I need to resort to a for loop?
I believe Purchase.objects().exclude(inventorylog__sold_out=True)
will do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With