Created
June 3, 2017 16:41
-
-
Save mhubig/26c4d90159a87dedd0338ca9c7debc13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create(self, validated_data): | |
# get the sections data | |
sections = validated_data.pop('sections', []) | |
user = self.context['request'].user | |
# Create the chapter instance | |
chapter = Chapter.objects.create(**validated_data) | |
# Create each section instance | |
for section in sections: | |
widgets = section.pop('widgets', []) | |
section.update({'chapter': chapter}) | |
section = Section.objects.create(**section) | |
# Create each widget instance | |
for widget in widgets: | |
widget.update({'section': section, 'user': user}) | |
widget = Widget.objects.create(**widget) | |
return chapter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment