Squashed commit of the following:

This commit is contained in:
smilerz
2021-09-05 11:18:57 -05:00
parent d1556f69c2
commit d33a49538e
13 changed files with 88 additions and 28 deletions

View File

@ -338,11 +338,11 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
def create(self, validated_data):
validated_data['name'] = validated_data['name'].strip()
validated_data['space'] = self.context['request'].space
supermarket = validated_data.pop('supermarket_category', None)
# supermarket = validated_data.pop('supermarket_category', None)
obj, created = Food.objects.get_or_create(**validated_data)
if supermarket:
obj.supermarket_category, created = SupermarketCategory.objects.get_or_create(name=supermarket['name'], space=self.context['request'].space)
obj.save()
# if supermarket:
# obj.supermarket_category, created = SupermarketCategory.objects.get_or_create(name=supermarket.name, space=self.context['request'].space)
# obj.save()
return obj
def update(self, instance, validated_data):