コード例 #1
0
ファイル: api.py プロジェクト: marcuslind90/lindshop
	def create_attribute(self, instance, validated_data):
		choice_data = validated_data.pop('attributechoice_set')
		validated_data['slug'] = slugify(validated_data['name'])

		attribute = Attribute(**validated_data)
		attribute.save()

		for choice in choice_data:
			choice_obj = AttributeChoice(attribute=attribute, **choice)
			choice_obj.save()

		return attribute
コード例 #2
0
ファイル: api.py プロジェクト: marcuslind90/lindshop
	def create(self, validated_data):
		# Seperate nested data...
		choice_data = validated_data.pop('attributechoice_set')

		# Create the Attribute with remaining data.
		attribute = Attribute(**validated_data)
		attribute.save()

		# Create the AttributeChoices with the nested data seperated above.
		for choice in choice_data:
			choice_obj = AttributeChoice(attribute=attribute, **choice)
			choice_obj.save()

		return attribute