fix bug of user edit
This commit is contained in:
@@ -109,18 +109,24 @@ class UserSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
mobile = attrs['mobile']
|
mobile = attrs['mobile']
|
||||||
username = attrs['username']
|
if 'username' in attrs.keys():
|
||||||
|
username = attrs['username']
|
||||||
|
|
||||||
if not self.instance:
|
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()
|
raise UserExistException()
|
||||||
|
|
||||||
elif self.instance:
|
elif self.instance:
|
||||||
if self.instance.mobile != mobile:
|
if self.instance.mobile != mobile:
|
||||||
if self.Meta.model.objects.filter(mobile=mobile).exists():
|
if self.Meta.model.objects.filter(mobile=mobile).exists():
|
||||||
raise UserExistException()
|
raise UserExistException()
|
||||||
if self.instance.username != username:
|
|
||||||
if self.Meta.model.objects.filter(username=username).exists():
|
if 'username' in attrs.keys():
|
||||||
raise UserExistException()
|
if self.instance.username != attrs['username']:
|
||||||
|
if self.Meta.model.objects.filter(username=attrs['username']).exists():
|
||||||
|
raise UserExistException()
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|||||||
@@ -43,3 +43,5 @@
|
|||||||
[2025-10-27 16:47:09,174] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
[2025-10-27 16:47:09,174] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
||||||
[2025-10-27 16:47:13,725] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
[2025-10-27 16:47:13,725] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
[2025-10-27 16:49:53,321] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
[2025-10-27 16:49:53,321] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
||||||
|
[2025-10-27 16:49:55,766] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||||
|
[2025-10-27 17:04:59,459] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
||||||
|
|||||||
Reference in New Issue
Block a user