【发布时间】:2023-03-28 01:27:01
【问题描述】:
CHOICE_FIELD_SET = {
'dependent': [
{'id': 1, 'name': "Spouse"},
{'id': 2, 'name': "Children"},
{'id': 3, 'name': "Parents"}
]
}
这是我的常量.py
@staticmethod
def validate_dependent_type(dependent_type):
if dependent_type > util_constants.CHOICE_FIELD_SET['dependent'].extend('id'):
raise serializers.ValidationError("Dependent can be of three types only")
return dependent_type
这是我的 serializer.py
如何仅验证 id 3 希望你理解这个问题,如果不明白,请在评论中提问
【问题讨论】:
-
所以需要检查依赖的id是否大于3?
-
我需要限制此列表中是否存在依赖类型然后只执行否则显示错误
标签: django python-3.x list dictionary django-rest-framework