[Answer]-Django models complex query

1👍

You can easily do queries that span (reverse) relationship:

TextObj.objects.filter(securitycheck__sharedWith=user, filename="foo")

https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships

Django offers a powerful and intuitive way to “follow” relationships in lookups, taking care of the SQL JOINs for you automatically, behind the scenes. To span a relationship, just use the field name of related fields across models, separated by double underscores, until you get to the field you want.

It works backwards, too. To refer to a “reverse” relationship, just use the lowercase name of the model.

Leave a comment