HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/aigenerator/AI-LG-backend/Ai_logo_generation/User/serializers.py
from rest_framework import serializers
from authorization.models import CustomUser
from .models import BillingAddress


class UserProfileSerializer(serializers.ModelSerializer):
    profile_image = serializers.FileField(required=False, allow_null=True)  
    class Meta:
        model = CustomUser 
        fields = ['first_name', 'last_name', 'profile_image', 'email','is_verified']

    def __init__(self, *args, **kwargs):
        # Dynamically adjust fields based on request method
        request_method = kwargs.pop('request_method', None)
        super(UserProfileSerializer, self).__init__(*args, **kwargs)

        if request_method == 'PATCH':
            # Only allow first_name, last_name, and profile_image to be updated
            self.Meta.fields = ['first_name', 'last_name', 'profile_image']
    
class BillingAddressSerializer(serializers.ModelSerializer):
    class Meta:
        model = BillingAddress
        fields = ['first_name', 'last_name', 'country_code', 'phone_number', 'address', 'city', 'state', 'postal_code']