filter all apis of organization city & province - cant remove own user or organoization
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import typing
|
||||
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.db.models import Q
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.authentication.exceptions import UserExistException
|
||||
from apps.authentication.models import (
|
||||
User,
|
||||
City,
|
||||
@@ -99,6 +101,13 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
}
|
||||
}
|
||||
|
||||
def validate(self, attrs):
|
||||
mobile = attrs['mobile']
|
||||
national_code = attrs['national_code']
|
||||
|
||||
if self.Meta.model.objects.filter(Q(mobile=mobile) | Q(national_code=national_code)).exists():
|
||||
raise UserExistException()
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom output """
|
||||
|
||||
@@ -133,6 +142,8 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
instance.nationality = validated_data.get('nationality')
|
||||
instance.ownership = validated_data.get('ownership')
|
||||
instance.address = validated_data.get('address')
|
||||
instance.address = validated_data.get('unit_name')
|
||||
instance.address = validated_data.get('unit_national_id')
|
||||
instance.photo = validated_data.get('photo')
|
||||
instance.province = validated_data.get('province', instance.province)
|
||||
instance.city = validated_data.get('city', instance.city)
|
||||
|
||||
Reference in New Issue
Block a user