fix bug of user edit

This commit is contained in:
2025-10-27 17:06:06 +03:30
parent 2e540e8109
commit 96d18ac488
2 changed files with 13 additions and 5 deletions

View File

@@ -109,18 +109,24 @@ class UserSerializer(serializers.ModelSerializer):
def validate(self, attrs):
mobile = attrs['mobile']
username = attrs['username']
if 'username' in attrs.keys():
username = attrs['username']
if not self.instance:
if self.Meta.model.objects.filter(Q(mobile=mobile) | Q(username=username)).exists():
if self.Meta.model.objects.filter(
Q(mobile=mobile) | Q(username=attrs['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.username != username:
if self.Meta.model.objects.filter(username=username).exists():
raise UserExistException()
if 'username' in attrs.keys():
if self.instance.username != attrs['username']:
if self.Meta.model.objects.filter(username=attrs['username']).exists():
raise UserExistException()
return attrs