19π
Now, I want to filter all videos which have a specific format, AND the
status code for that format is 10 (ready to use). How can I do that?
(assuming that f is the format)
The code that you posted does exactly what you want:
Video.objects.filter(media__formats=f, media__mediaformat__status=10)
This is documented in the filter()
documentation:
Multiple parameters are joined via AND in the underlying SQL
statement.
11π
You can chain the filters together for an βANDβ construct.
Videos where the format is f
AND the formatβs status is 10
Video.objects.filter(media__formats=f).filter(media__mediaformat__status=10)
- Django reverse error: NoReverseMatch
- How can i get all models in django 1.8
- How to convert request.user into a proxy auth.User class?
- Django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
- Gunicorn sync workers spawning processes
3π
Probably not relevant for the OP, but might be for others like me who found this thread while searching for the right answer.
Ludwik got it right, but the section in the documentation that explains all of this, as well as how to do excludes, is in the queries documentation.
Note that splitting the filter into two filter
calls like Chris suggested will give you the exact opposite result: it will search for a video that has a media format f
and that has a media format, not necessarily the same media format, with a status of 10.
- Django: How to check if something is an email without a form
- Return image url in Django Rest Framework