Serializers в Python помогите разобраться

Всем привет, подскажите пожалуйста, обучаюсь, ревью прислали изменить, не понимаю как правильно тут сделать, помогите пожалуйста. Часть кода из всего что скинул снизу

def validate_tags(self, value):
    if not value:
        raise ValidationError({'Выберите теги.'})
    values_slug = [i for i in value] ------------------------------------------------------"""РЕВЬЮ написал - Лишняя переменная"""
    if len(values_slug) != len(set(values_slug)):
        raise ValidationError({'Теги повторяются.'})
    return value


**def validate_ingredients(self, value):
        if not value:
            raise ValidationError({'Выберите ингредиенты.'})
        len_amount = [i for i in value if int(i['amount']) <= 0]
        if len_amount: -------------------------"""РЕВЬЮ написал - Некорректная проверка - может быть всего 5 ингредиентов и два из них с отрицательным кол-ом"""
            raise ValidationError({'Выберите кол-во ингредиентов.'})
        values_id = [i['id'] for i in value]
        if len(values_id) != len(set(values_id)):
            raise ValidationError({'Ингредиенты повторяются.'})
        return value**

Вся часть кода отвечающая за создания, редактирования и удаления рецепта

class CreateRecipeSerializer(ModelSerializer):
    """ Сериализатор  создания, редактирования и удаления рецепта"""
    author = UsersSerializer(read_only=True)
    tags = PrimaryKeyRelatedField(queryset=Tag.objects.all(), many=True)
    ingredients = CreateRecipeIngredientSerializer(many=True)
    cooking_time = IntegerField()
    image = Base64ImageField(use_url=True)
    class Meta:
        model = Recipe
        fields = ['id', 'image', 'tags', 'author',
                  'ingredients', 'name', 'text', 'cooking_time']
    def validate_tags(self, value):
        if not value:
            raise ValidationError({'Выберите теги.'})
        values_slug = [i for i in value]
        if len(values_slug) != len(set(values_slug)):
            raise ValidationError({'Теги повторяются.'})
        return value
    def validate_ingredients(self, value):
        if not value:
            raise ValidationError({'Выберите ингредиенты.'})
        len_amount = [i for i in value if int(i['amount']) <= 0]
        if len_amount:
            raise ValidationError({'Выберите кол-во ингредиентов.'})
        values_id = [i['id'] for i in value]
        if len(values_id) != len(set(values_id)):
            raise ValidationError({'Ингредиенты повторяются.'})
        return value
    @atomic
    def create_ingredients(self, recipe, ingredients):
        IngredientRecipe.objects.bulk_create(
            [IngredientRecipe(
                recipe=recipe,
                ingredient_id=row.get('id'),
                amount=row.get('amount'),
            ) for row in ingredients])
    @atomic
    def create(self, validated_data):
        request = self.context.get('request')
        tags = validated_data.pop('tags')
        ingredients = validated_data.pop('ingredients')
        recipe = Recipe.objects.create(author=request.user,
                                       **validated_data)
        self.create_ingredients(recipe, ingredients)
        recipe.tags.set(tags)
        return recipe
    @atomic
    def update(self, instance, validated_data):
        ingredients = validated_data.pop('ingredients')
        IngredientRecipe.objects.filter(recipe=instance).delete()
        self.create_ingredients(instance, ingredients)
        return super().update(instance, validated_data)
    def to_representation(self, instance):
        return RecipeSerializer(
            instance,
            context={'request': self.context.get('request')}
        ).data

Ответы (0 шт):