예제 #1
0
    def all_ids_must_exist(cls, sub_meals):
        ids = [meal for meal in sub_meals if isinstance(meal, int)]
        meals = Meal.select().where(Meal.id.in_(ids))
        existing_ids = {meal.id for meal in meals}
        missing_ids = set(ids) - existing_ids
        if len(meals) != len(ids):
            raise ValueError(f"Meal ids {missing_ids} do not exist.")

        for meal in meals:
            # we need to make sure that sub-meals used in other meal-trees are not
            # stolen from there, so we make a copy by removing the id.
            meal.id = None
        return meals
예제 #2
0
def get_meals():
    return list(Meal.select())