def create(body):
""" Create threshold
"""
try:
category = Category.objects.get(name=body['category'])
if ReportThreshold.objects.filter(category=category).exists():
raise BadRequest('Threshold already exists for this category')
body['category'] = category
threshold, created = ReportThreshold.objects.get_or_create(**body)
except (KeyError, FieldError, IntegrityError, ObjectDoesNotExist):
raise BadRequest('Missing or invalid fields in body')
if not created:
raise BadRequest('Threshold already exists')
return model_to_dict(threshold)
评论列表
文章目录