1

Say I have a user id, and the users table also has a manytomany field "teacher id". This points to the teachers table. There is a substitutes table where a foreign key is teacher id, meaning that each substitute can only substitute for one teacher, but there may be many substitutes to that teacher. (This is not really what my fields represent, but I'm just using an example.) How, in Django, would I get all the substitute id's for all teachers who are teachers for a given user id? I know how to do it in SQL, but not really sure how the Django version is.

(This is similar to a question I had before, but not the same!)

1
  • You need to have a good read of the Django QuerySet Documentation which explains exactly how to do this sort of query. Commented Nov 1, 2013 at 1:41

1 Answer 1

2

You can use something like this:

Substitute.objects.filter(teacher__user=user.pk)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.