【发布时间】:2015-05-30 17:03:18
【问题描述】:
有没有办法覆盖或阻止 django rest 框架中的验证错误。例如,如果我有以下代码
class Function(models.Model):
name = models.CharField(max_length=30, unique=True)
我需要某种方式来阻止 name 的 unique=True。如何在序列化程序中处理?
class FunctionSerializerWithOnlyName(serializers.ModelSerializer):
def validate_name(self, value):
# it is always returning name needs to be unique even if i raise another error
return value
class Meta:
model = Function
fields = ( 'name',)
【问题讨论】:
标签: django rest python-2.7 django-rest-framework