[Answered ]-How can I access the elements of a foreign set for a model in Django's get_context_data method?

2👍

You are referring to the model, you need to refer to the instance (the object for which the view is showing the details) as relations are for instances and not models. You can get the instance with self.get_object():

def get_context_data(self, **kwargs):
    context = super(QuizDetail, self).get_context_data(**kwargs)
    obj = self.get_object()
    passed_questions = obj.quizquestion_set.filter(...)
    return context

Leave a comment