[Fixed]-Can't seem to use optional foreign key relationships when creating new object using Django+AngularJS

1👍

You need to set the read_only attribute on the ‘interval’ and ‘statements’ fields

class ProjectSerializer(serializers.ModelSerializer):
    intervals = IntervalSerializer(many=True, read_only=True)
    statements = StatementSerializer(many=True, read_only=True)

    class Meta:
       model = Project
       fields = ('id', 'project_name', 'user', 'intervals','statements')

or you can specify the read_only fields like this,

class Meta:
    model = Project
    fields = ('id', 'project_name', 'user', 'intervals','statements')
    read_only_fields = ('intervals','statements')

Leave a comment