Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def validate(self, attrs):
whatsapp = attrs.get('whatsapp', self.object.whatsapp)
whatsapp_h = attrs.get('whatsapp_h', self.object.whatsapp_h)
prontuario = attrs.get("prontuario", self.object.prontuario
try:
obj = tb_Paciente.objects.filter(whatsapp=whatsapp, whatsapp_h=whatsapp_h, prontuario=prontuario).exists
()
except tb_Paciente.DoesNotExist:
return attrs
if self.object and obj.id == self.object.id:
return attrs
else:
raise serializers.ValidationError('Este dado já existe na nossa base')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment