Filtering DJango QuerySet using Foreign Key from Another Model

It makes me question why there is a distinction between
and
in the first place. Perhaps it’s worth considering if a single model could serve both types of media, as relying on something like ContentTypes can be more complicated than having a single model. If you want more information on ContentTypes, try this solution: use the framework to create a generic and reusable approach for handling multiple models.


Solution:

To retrieve student applications for a recruiter’s job postings, the following query can be used:

# Retrieve a recruiter from `User` data model
$ recruiter = User.objects.get(email=)
# Now, Query student applications to our recruiter's job postings
$ student_applications = StudentApplication.objects.filter(job_fk__recruter_id=recruiter)

Hope it helps.

Frequently Asked Questions