Hello everyone! I'm new in Django. 
I have a serializer with nested serializer like this: 

 ################ Project Serializer with nested customer serializer 
###########################

class ProjectSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(required=False) 
    customer = CustomerSerializer(required=True)

    class Meta: 
        model = Project
        fields = '__all__'
        
    def __init__(self, customer_serializer_included=True, *args, **kwargs):
        super(ProjectSerializer, self).__init__(*args, **kwargs)
        self.customer = 
CustomerSerializer(required=customer_serializer_included)

########### BillingActivitySerializer that uses Project serializer (without 
nested serializer) ###########################

class BillingActivitySerializer(serializers.ModelSerializer):
     id = serializers.IntegerField(required=False) 
     project = ProjectSerializer(required=True, 
customer_serializer_included = False)

The problem is that everytime i use the project serializer, also nested 
serializer are used too. I'd like to exclude the nested serializer. I've 
try to do this in the __init__ but Django gives always a 400 Bad request

Response: {
  "project": {
    "customer": [
      "This field is required."
    ]
  }
}



Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ddcb9ea-8fe1-4391-a268-10fe41d8c95dn%40googlegroups.com.

Reply via email to