fix update user data bug
This commit is contained in:
@@ -101,6 +101,7 @@ class UserViewSet(ModelViewSet):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if serializer.is_valid():
|
||||
user = serializer.update(self.queryset.get(id=pk), validated_data=request.data)
|
||||
|
||||
if 'organization' in request.data.keys(): # noqa
|
||||
organization = CustomOperations().custom_update( # update organization for user
|
||||
request=request,
|
||||
|
||||
@@ -97,6 +97,12 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
extra_kwargs = {
|
||||
'password': {
|
||||
'required': False
|
||||
},
|
||||
'username': {
|
||||
'required': False
|
||||
},
|
||||
"national_code": {
|
||||
'required': False
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,15 +110,16 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
""" Custom output """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
if instance.bank_information.all():
|
||||
representation['bank_account'] = BankAccountSerializer(
|
||||
instance.bank_information.all(), many=True
|
||||
).data
|
||||
if isinstance(instance, User):
|
||||
if instance.bank_information.filter().exists():
|
||||
representation['bank_account'] = BankAccountSerializer(
|
||||
instance.bank_information.all(), many=True
|
||||
).data
|
||||
|
||||
if instance.city:
|
||||
representation['city_name'] = instance.city.name
|
||||
if instance.province:
|
||||
representation['province_name'] = instance.province.name
|
||||
if instance.city:
|
||||
representation['city_name'] = instance.city.name
|
||||
if instance.province:
|
||||
representation['province_name'] = instance.province.name
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0 on 2025-06-15 09:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0021_city_province'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='mobile',
|
||||
field=models.CharField(max_length=18, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='national_code',
|
||||
field=models.CharField(max_length=16, null=True),
|
||||
),
|
||||
]
|
||||
@@ -7,9 +7,9 @@ from django.db import models
|
||||
|
||||
|
||||
class User(AbstractUser, BaseModel):
|
||||
mobile = models.CharField(max_length=18)
|
||||
mobile = models.CharField(max_length=18, null=True)
|
||||
phone = models.CharField(max_length=18, null=True)
|
||||
national_code = models.CharField(max_length=16)
|
||||
national_code = models.CharField(max_length=16, null=True)
|
||||
birthdate = models.DateTimeField(null=True)
|
||||
nationality = models.CharField(max_length=20, null=True)
|
||||
ownership_types = (
|
||||
|
||||
@@ -145,9 +145,9 @@ class UserRelationSerializer(serializers.ModelSerializer):
|
||||
""" update user relation object """
|
||||
|
||||
if validated_data.get('role'):
|
||||
instance.role = validated_data.get('role', instance.role.id)
|
||||
instance.role = Role.objects.get(id=validated_data.get("role"))
|
||||
if validated_data.get('organization'):
|
||||
instance.organization = validated_data.get('organization', instance.organization.id)
|
||||
instance.organization = Organization.objects.get(id=validated_data.get('organization'))
|
||||
instance.save()
|
||||
instance.permissions.clear()
|
||||
instance.permissions.add(*(validated_data.get('permissions', instance.permissions)))
|
||||
|
||||
Reference in New Issue
Block a user