Created
July 12, 2021 16:40
-
-
Save Marlysson/b4a18fc90dc7716c670d90c415ee9da0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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