<commit_before>from django.contrib.auth.models import User
from rest_framework import serializers
from django_countries.serializer_fields import CountryField

from .models import Artist, Staff, Organization, FresnoyProfile


class FresnoyProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = FresnoyProfile
#        exclude = ('user',)

    id = serializers.ReadOnlyField()
    birthplace_country = CountryField(default="FR")
    homeland_country = CountryField(default="FR")
    residence_country = CountryField(default="FR")


class ArtistSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Artist
        exclude = ('updated_on',)


class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'first_name', 'last_name', 'email', "profile")

    profile = FresnoyProfileSerializer()


class StaffSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Staff<commit_msg>api user serializer save and update user profile<commit_after>from django.contrib.auth.models import User
from rest_framework import serializers
from django_countries.serializer_fields import CountryField

from .models import Artist, Staff, Organization, FresnoyProfile


class FresnoyProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = FresnoyProfile
        exclude = ('user',)

    id = serializers.ReadOnlyField()
    birthplace_country = CountryField(default="FR")
    homeland_country = CountryField(default="FR")
    residence_country = CountryField(default="FR")
    #user = serializers(source="user")


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'first_name', 'last_name', 'email', 'profile')

    profile = FresnoyProfileSerializer(required=False)

    def create(self, validated_data):
        profile_data = validated_data.pop('profile')
        user = User.objects.create(**validated_data)
        UserProfile.objects.create(**profile_data)
        return user

    def update(self, instance, validated_data):
        profile_data = validated_data.pop('profile')

        # Update User data
        instance.first_name = validated_data.get('first_name', instance.first_name)
        instance.last_name = validated_data.get('last_name', instance.last_name)
        instance.email = validated_data.get('email', instance.email)

        # Update UserProfile data
        if not instance.profile:
            FresnoyProfile.objects.create(user=instance, **profile_data)

        #set Values for UserProfile
        for item in profile_data:
            value = profile_data.get(item)
            setattr(instance.profile, item, value)

        instance.save()
        return instance


class ArtistSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Artist
        exclude = ('updated_on',)




class StaffSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Staff
{'fraction_non_alphanumeric': 0.08974778905994105, 'fraction_numerical': 0.0, 'mean_word_length': 3.749611197511664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1032790', 'n_tokens_mistral': 827, 'n_tokens_neox': 787, 'n_words': 186}