[Answer]-Django ORM relation to a non unique filed

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.

0👍

Aren’t you looking for Many-to-Many extra fields?

👤I S

Leave a comment