models.py
class Topic(Model):
pass
class Question(Model):
topic = models.Foreignkey(Topic)
class Syllabus(Model):
topic = models.Foreignkey(Topic)
#The Bridge Model
class Test_Syllabus(Model):
test = models.Foreignkey(Test)
syllabus = models.Foreignkey(Syllabus)
class Test (Model):
pass
I have a test object as follows:
test = Test.objects.get(id=pk)
Using the test object, I want to get the related queryset of questions. So, I tried the following code:
questions = test.test_syllabus_set.all() #don't know how to go further from here
I think it has something to do with select_related and prefetch_related. Please help me out with a perfect query for this use case.