Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Created July 12, 2021 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marlysson/b4a18fc90dc7716c670d90c415ee9da0 to your computer and use it in GitHub Desktop.
Save Marlysson/b4a18fc90dc7716c670d90c415ee9da0 to your computer and use it in GitHub Desktop.
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