Example #1
0
def filter(search):
    sandwichs = list(models.Sandwich.objects.filter(name__contains=search))

    ingredients = Ingredient.filter(search)
    for ingredient in ingredients:
        itens = models.SandwichIngredient.objects.filter(ingredient=ingredient)

        for item in itens:
            if item.sandwich not in sandwichs:
                sandwichs.append(item.sandwich)

    return sandwichs
Example #2
0
def filter_submit(request):
    if request.GET:
        name = request.GET.get("name")
        if name:
            ingredients = Ingredient.filter(name)

            if len(ingredients) > 0:
                return return_list(request, ingredients)
            else:
                messages.error(request, 'Ingrediente nao encontrado')
        else:
            messages.error(request, 'Nome não pode estar em branco')
    else:
        messages.error(request, 'Erro durante a solicitação')

    return redirect('/ingredient/filter')
Example #3
0
 def test_filter_ingredient(self):
     ingredients = Ingredient.filter('Pã')
     self.assertNotEqual(len(ingredients),0)