python - 将变量名称作为“字符串”传递
问题描述
有没有办法通过“性别”附加它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")
解决方案
推荐阅读
- expression - Snaplogic - 表达式语言语法 - 唯一的数组值
- python - 我想要一个函数来检查输入是否是 int 以及它是否在 python 中的要求范围内
- node.js - 在 NodeJS ClamScan 中产生错误 /usr/bin/clamscan
- parsing - 在编译器构造中有两个语义分析阶段是否很常见?
- web - Safari 快速网站搜索 | 如何告诉 Safari 我的全文搜索的工作方式?
- java - Sping:@Autowired 与构造函数注入
- php - SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;在实时服务器上使用 DENSE_RANK()
- android - 添加按钮和功能哟 appWidget
- javascript - 将类似 JSON 的字符串转换为 JSON
- javascript - JQuery 根据其他动态添加的输入字段验证动态添加的输入字段