change user validation from national_code to user name
This commit is contained in:
@@ -109,17 +109,17 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
|
||||
def validate(self, attrs):
|
||||
mobile = attrs['mobile']
|
||||
national_code = attrs['national_code']
|
||||
username = attrs['username']
|
||||
|
||||
if not self.instance:
|
||||
if self.Meta.model.objects.filter(Q(mobile=mobile) | Q(national_code=national_code)).exists():
|
||||
if self.Meta.model.objects.filter(Q(mobile=mobile) | Q(username=username)).exists():
|
||||
raise UserExistException()
|
||||
elif self.instance:
|
||||
if self.instance.mobile != mobile:
|
||||
if self.Meta.model.objects.filter(mobile=mobile).exists():
|
||||
raise UserExistException()
|
||||
if self.instance.national_code != national_code:
|
||||
if self.Meta.model.objects.filter(national_code=national_code).exists():
|
||||
if self.instance.username != username:
|
||||
if self.Meta.model.objects.filter(username=username).exists():
|
||||
raise UserExistException()
|
||||
|
||||
return attrs
|
||||
|
||||
Reference in New Issue
Block a user