From 6887140a4e28b1c21ad6b9934c525a308257e5f2 Mon Sep 17 00:00:00 2001 From: Ching Date: Tue, 5 Oct 2021 15:59:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(DailyRecipe=20generate=5Frecipe):=20[M]=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E8=8F=9C=E8=B0=B1=E6=97=B6=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [M] 修复当获取不到随机菜谱时报错的问题 Signed-off-by: Ching --- recipe/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipe/models.py b/recipe/models.py index eca4b6d..b332418 100644 --- a/recipe/models.py +++ b/recipe/models.py @@ -52,7 +52,7 @@ class DailyRecipe(models.Model): recipe = Recipe.objects.filter( recipe_type=const.RECIPE_TYPE_MEAT, ).order_by('?').first() - if recipe.id not in recipes and recipe.id not in prev_recipes: + if recipe and recipe.id not in recipes and recipe.id not in prev_recipes: recipes.append(recipe.id) break if retry <= 0: @@ -65,7 +65,7 @@ class DailyRecipe(models.Model): recipe = Recipe.objects.filter( recipe_type=const.RECIPE_TYPE_VEGETABLE, ).order_by('?').first() - if recipe.id not in recipes and recipe.id not in prev_recipes: + if recipe and recipe.id not in recipes and recipe.id not in prev_recipes: recipes.append(recipe.id) break retry -= 1