I have a model with a many-to-many field like this:
class BillingMonth(models.Model):
month = models.IntegerField(min=1, max=12)
class BillingCycle(models.Model):
description = models.CharField()
months_billed = models.ManyToManyField(BillingMonth)
Each BillingCycle (monthly, quarterly, etc) will get billed in one or more months. The rental equipment model looks like this:
class RentalEquipment(models.Model):
description = models.CharField()
billing_cycle = models.ForeignKey(BillingCycle)
How do I find all RentalEquipment that should be billed on a given month? This doesn’t seem to work:
billing_month = BillingMonth(month=8)
RentalEquipment.objects.filter(billing_cycle__months_billed=billing_month)
Alternatively, is having a ManyToMany relationship overkill for the BillingCycle model? Is there a better way to include an array of dates?
It looks like I can break out the query like so: