post food_tree bug fixing

This commit is contained in:
smilerz
2021-09-04 16:41:57 -05:00
parent 738387ccf0
commit b147c975b8
19 changed files with 90 additions and 97 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):