首页 > 解决方案 > 将变量名称作为“字符串”传递

问题描述

有没有办法通过“性别”附加它QuestionFocus然后得到背后的东西QuestionFocus.GENDER?我当然可以通过QuestionFocus.GENDER,但它会比(可能)需要的时间更长。

def get_answers(question_focus):
    return Answer.objects.filter(
        response_id__in=get_super_guests().values_list("id", flat=True),
        question__focus=QuestionFocus.question_focus,
    ).order_by("-created")

context["genders"] = get_answers("GENDER")

标签: python

解决方案


推荐阅读