fix/forzar-carga-acuses
This commit is contained in:
@@ -9,7 +9,7 @@ class CustomUserSerializer(serializers.ModelSerializer):
|
||||
Serializer for the CustomUser model.
|
||||
"""
|
||||
|
||||
password = serializers.CharField(write_only=True)
|
||||
password = serializers.CharField(write_only=True, required=False)
|
||||
groups = serializers.PrimaryKeyRelatedField(queryset=Group.objects.all(), many=True, required=False)
|
||||
rfc = serializers.PrimaryKeyRelatedField(
|
||||
queryset=Importador.objects.all(),
|
||||
@@ -23,6 +23,17 @@ class CustomUserSerializer(serializers.ModelSerializer):
|
||||
fields = ['id', 'username', 'email', 'first_name', 'last_name', 'password', 'profile_picture', 'organizacion', 'is_importador', 'rfc', 'is_active', 'is_superuser', 'groups']
|
||||
read_only_fields = ['id', 'organizacion', 'is_superuser']
|
||||
|
||||
def validate_password(self, value):
|
||||
if not value or not value.strip():
|
||||
raise serializers.ValidationError("La contraseña no puede estar vacía o contener solo espacios.")
|
||||
return value
|
||||
|
||||
def validate(self, attrs):
|
||||
# En create, la contraseña es obligatoria
|
||||
if self.instance is None and not attrs.get('password'):
|
||||
raise serializers.ValidationError({"password": "Este campo es requerido."})
|
||||
return attrs
|
||||
|
||||
def create(self, validated_data):
|
||||
groups = validated_data.pop('groups', [])
|
||||
rfcs = validated_data.pop('rfc', [])
|
||||
|
||||
Reference in New Issue
Block a user