Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi,

Can you help me how to disable creating nested objects ?

I have serializers like this:
(Employee has ForeignKey to Team)


class TeamSerializer(serializers.ModelSerializer):
    class Meta:
        model = Team
        fields = ('id', 'name')
class EmployeeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = ('id', 'name', 'surname', 'team')
        depth = 1

or instead could be:


    class EmployeeSerializer(serializers.ModelSerializer):
        team = TeamSerializer()
        class Meta:
            model = Employee
            fields = ('id', 'name', 'surname', 'team')

when i post json (create employee)

{

     name: "name",
     surname: "surname",
     team: {
       id: 1,
       name: "Web Team"
     }

object employee creates but also object team... is there any way to disable creating team object together with employee ? i just want to create employee and set selected team (curently in database) to employee

And on GET (list) i would like to be able to retrieve data like:


    {
     name: "name",
     surname: "surname",
     team: {
        id: 1,
        name: "Web Team"
     }

not like that


    {
     name: "name",
     surname: "surname",
     team: 1
    }

Is there any way to to that in django rest framework (also iam using angular)
Regards

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.