【发布时间】:2019-07-26 15:18:55
【问题描述】:
我希望能够通过名称和值来解析查询字符串的参数。 django-filters 或 django-rest-framework 可以做到这一点吗?
示例:/api/user/?custom_field_{id}={value}
class UserFilter(django_filters.FilterSet):
custom_field{id} = django_filters.ModelChoiceFilter(
queryset=CustomField.objects.all(), method="filter_by_custom_field"
)
def filter_by_custom_field(self, queryset, name, value):
# How can I get access to the {id} as well as the value in here?
pass
上面的语法是不允许的(custom_field{id}),但这是一个例子来展示我想要实现的目标。
【问题讨论】:
-
欢迎来到 StackOverflow!分享您的研究对每个人都有帮助。告诉我们您尝试了什么以及为什么它不能满足您的需求。这表明您已经花时间尝试帮助自己,它使我们免于重复明显的答案,最重要的是它可以帮助您获得更具体和相关的答案!另见:How to Ask
标签: python django django-rest-framework django-filter