fixed serializer for food

This commit is contained in:
smilerz
2021-08-31 15:29:16 -05:00
parent 70089998fe
commit 93d261b529
2 changed files with 9 additions and 9 deletions

View File

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

View File

@@ -277,14 +277,14 @@ else:
# } # }
# SQLite testing DB # SQLite testing DB
# DATABASES = { DATABASES = {
# 'default': { 'default': {
# 'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
# 'OPTIONS': ast.literal_eval(os.getenv('DB_OPTIONS')) if os.getenv('DB_OPTIONS') else {}, 'OPTIONS': ast.literal_eval(os.getenv('DB_OPTIONS')) if os.getenv('DB_OPTIONS') else {},
# 'NAME': 'db.sqlite3', 'NAME': 'db.sqlite3',
# 'CONN_MAX_AGE': 600, 'CONN_MAX_AGE': 600,
# } }
# } }
CACHES = { CACHES = {
'default': { 'default': {