def validate(self, data):
for field in self.Meta.fields:
try:
model_field = self.Meta.model._meta.get_field(field)
if hasattr(model_field, 'default') and model_field.default != NOT_PROVIDED and \
data.get(field, NOT_PROVIDED) is None:
data.pop(field)
except FieldDoesNotExist:
pass
return super(NullToDefaultMixin, self).validate(data)
评论列表
文章目录