i am confuse on which is best to validation in serializer or in model (inside models.py save method) in django?
Serializer code
def save(self, force_insert=False, force_update=False, using=None,update_fields=None):
if self.x > self.y:
raise BadRequest(details={'message':'x should be less than y.'})
return super(xx, self).save()
or
Models code
def validate(self, attrs):
if attrs['x'] > attrs['y']:
raise BadRequest(details={'message':'x should be less than y.'})
return attrs
which is most best practical? and how we can achieved thick model and thin view?