[Answer]-Optimal solution for filtering inherited django models


Your File model is actually a custom many to many relationship. I would use a ManyToMany in the Image model to the user model.

class Image(models.Model):
   users = models.ManyToManyField(...)

for querying it would go like this:

a) find cameras a user has


b) Filter user images by camera

Image.objects.filter(users=the_user_in_subject, camera='camera type')

Also if your File model has other fields as well, you can use the through option https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

Leave a comment