File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -108,23 +108,21 @@ def clean(self):
108108 - минимальное количество ингредиента
109109 при добавлении рецепта через админ панель.
110110 """
111- if not self .tags .exists ():
112- raise ValidationError (
113- {'tags' : 'Необходимо указать хотя бы один тег.' })
114111 if self .cooking_time < MIN_COOKING_TIME :
115112 raise ValidationError ({
116113 'cooking_time' : f'Минимальное время '
117114 f'приготовления: { MIN_COOKING_TIME } ' })
118-
119- ingredients_list = self .recipe_ingredients .all ()
120- if not ingredients_list :
115+ if not self .pk and not self .tags .count ():
116+ raise ValidationError (
117+ {'tags' : 'Необходимо указать хотя бы один тег.' })
118+ if not self .recipe_ingredients .exists ():
121119 raise ValidationError (
122120 {'recipe_ingredients' : 'Список ингредиентов '
123121 'не может быть пустым.' })
124122
125123 ingredients_ids_set = set ()
126- for ingredient in ingredients_list :
127- ingredient_id = ingredient .ingredient_id
124+ for ingredient in self . recipe_ingredients . all () :
125+ ingredient_id = ingredient .ingredient . id
128126 if ingredient_id in ingredients_ids_set :
129127 raise ValidationError (
130128 {'recipe_ingredients' : 'Ингредиенты не должны '
You can’t perform that action at this time.
0 commit comments