1👍
I think you’re almost there, except that I would define the imei
field on CustomerIMEI
as an actual ForeignKey – you can specify the field to link to in the target table, like this:
imei = models.ForeignKey(Phone, to_field='imei')
Now, you can use that CustomerIMEI
as the through
field of a many-to-many relationship from Customer:
phones = models.ManyToManyField(Phone, through=CustomerIMEI)
and now your suggested syntax customer.phones.filter(day='some day')
will just work.
- [Answer]-Heroku deployment busted, operational error
- [Answer]-ModelForm instance with ForeignKey – unexpected behaviour
- [Answer]-Django Tastypie – Filter for "OR" Operation
Source:stackexchange.com