Esempio n. 1
0
	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
Esempio n. 2
0
	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