I used to use allow_add_remove=True which was availabe in django rest 2.0 for writing nestable serializer but its not available in 3.0 and i am having hard time implementing it.
I want to do something like this
class UserSerialzier():
project = ProjectSerilaizer(many=True, allow_add_remove=True, read_only=False)
class ProjectSerialzier():
ideas = IdeaSerilaizer(many=True, allow_add_remove=True, read_only=False)
sources = SourceSerilaizer(many=True, allow_add_remove=True, read_only=False)
class IdeaSerialzier():
pass
class SourceSerialzier():
pass
Now i am not able to know how can i implement the allow_add_remove behavior in DRF 3.0
I am confused that do i need to override create
and update
method of UserSerializer
or i need to create separate IdeaListSerializer for every model
class IdeaListSerializer(serializers.ListSerializer):
def create(self, validated_data):
ideas = [Idea(**item) for item in validated_data]
return Ideas.objects.bulk_create(books)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…