From 0b1d8bbd5fea5944f190bcbc98fc0f99126a44b6 Mon Sep 17 00:00:00 2001 From: smilerz Date: Fri, 1 Oct 2021 14:20:41 -0500 Subject: [PATCH] WIP --- cookbook/models.py | 4 ++-- cookbook/serializer.py | 2 +- cookbook/tests/conftest.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cookbook/models.py b/cookbook/models.py index d4d7d698..e3385435 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -488,7 +488,7 @@ class Food(ExportModelOperationsMixin('food'), TreeModel, PermissionModelMixin): description = models.TextField(default='', blank=True) on_hand = models.BooleanField(default=False) inherit = models.BooleanField(default=False) - ignore_inherit = models.ManyToManyField(FoodInheritField, blank=True) # is this better as inherit instead of ignore inherit? which is more intuitive? + ignore_inherit = models.ManyToManyField(FoodInheritField, blank=True) # is this better as inherit instead of ignore inherit? which is more intuitive? space = models.ForeignKey(Space, on_delete=models.CASCADE) objects = ScopedManager(space='space', _manager_class=TreeManager) @@ -827,7 +827,7 @@ class ShoppingListRecipe(ExportModelOperationsMixin('shopping_list_recipe'), mod def get_owner(self): try: - return self.entries.first().created_by or self.shoppinglist_set.first().created_by + return getattr(self.entries.first(), 'created_by', None) or getattr(self.shoppinglist_set.first(), 'created_by', None) except AttributeError: return None diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 24c333f4..ce21111b 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -365,7 +365,7 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False) recipe = RecipeSimpleSerializer(allow_null=True, required=False) shopping = serializers.SerializerMethodField('get_shopping_status') - ignore_inherit = FoodInheritFieldSerializer(many=True) + ignore_inherit = FoodInheritFieldSerializer(allow_null=True, many=True, required=False) recipe_filter = 'steps__ingredients__food' diff --git a/cookbook/tests/conftest.py b/cookbook/tests/conftest.py index 48c4e9c6..23f71e1a 100644 --- a/cookbook/tests/conftest.py +++ b/cookbook/tests/conftest.py @@ -5,10 +5,10 @@ import uuid import pytest from django.contrib import auth -from django.contrib.auth.models import User, Group +from django.contrib.auth.models import Group, User from django_scopes import scopes_disabled -from cookbook.models import Space, Recipe, Step, Ingredient, Food, Unit +from cookbook.models import Food, Ingredient, Recipe, Space, Step, Unit # hack from https://github.com/raphaelm/django-scopes to disable scopes for all fixtures @@ -52,8 +52,8 @@ def get_random_recipe(space_1, u1_s1): internal=True, ) - s1 = Step.objects.create(name=uuid.uuid4(), instruction=uuid.uuid4(), space=space_1, ) - s2 = Step.objects.create(name=uuid.uuid4(), instruction=uuid.uuid4(), space=space_1, ) + s1 = Step.objects.create(name=str(uuid.uuid4()), instruction=str(uuid.uuid4()), space=space_1, ) + s2 = Step.objects.create(name=str(uuid.uuid4()), instruction=str(uuid.uuid4()), space=space_1, ) r.steps.add(s1) r.steps.add(s2) @@ -63,8 +63,8 @@ def get_random_recipe(space_1, u1_s1): Ingredient.objects.create( amount=1, food=Food.objects.get_or_create(name=str(uuid.uuid4()), space=space_1)[0], - unit=Unit.objects.create(name=uuid.uuid4(), space=space_1, ), - note=uuid.uuid4(), + unit=Unit.objects.create(name=str(uuid.uuid4()), space=space_1, ), + note=str(uuid.uuid4()), space=space_1, ) ) @@ -73,8 +73,8 @@ def get_random_recipe(space_1, u1_s1): Ingredient.objects.create( amount=1, food=Food.objects.get_or_create(name=str(uuid.uuid4()), space=space_1)[0], - unit=Unit.objects.create(name=uuid.uuid4(), space=space_1, ), - note=uuid.uuid4(), + unit=Unit.objects.create(name=str(uuid.uuid4()), space=space_1, ), + note=str(uuid.uuid4()), space=space_1, ) )