D
D
Denis Pupchenko2017-05-03 22:16:16
Django
Denis Pupchenko, 2017-05-03 22:16:16

How to get current user in model method?

In template:
{{test_question.get_true_user_quest}}

class Test_question(models.Model):
    test = models.ForeignKey(Tests)
    question = models.ForeignKey(Question)

    def get_true_user_quest(self):
        user = ????
        #получить ответы конкретного пользователя на данный вопрос (из Test_questuon) в контексте текущего теста
        answer_user_all_in_question_in_test=self.test.user_answer_set.filter(question_id=self.question.id, user=user)

How to find the current user?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question