Let's say this pseudocode represents models to work with
class Quiz():
name = models.CharField()
class Answer():
quiz = models.ForeignKey(Quiz)
answer_text = models.CharField()
I would like to trace raw SQL, so let's also import from django.db import connection
print(Answer.objects.all().select_related('quiz').query)
ok, here we have inner join under the hood
>>> a = Answer.objects.all()
>>> print(a[0].quiz.query)
however the latter example throws AttributeError: 'Quiz' object has no attribute 'query'
Could you tell if there are any ways of tracing raw sql more effectively? Which way is the best?
I'm practicing more complicated prefetch_related
and select_related
queries.
Thanks