How to write if and else conditions in Django

I wanted to save email in email Model if email is coming from frontend,, else save phone number in phone model if phone is coming else send error

 def post(self,request):  
        if request.data['email']:
            serializeObj = EmailSerializer(data = request.data)
            if serializeObj.is_valid():
                serializeObj.save()
                return Response('Email success')
        else:
            serializeObj = PhoneSerializer(data = request.data)
            if serializeObj.is_valid():
                serializeObj.save()
                return Response('Phone success')
        return Response(send error)
Back to Top