Beispiel #1
0
def create_food(request):
    if request.method == "POST":
        form = FoodForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            form = FoodForm()
            return render(request, 'food/create_food.html', {'form': form})
    else:
        form = FoodForm()
        return render(request, 'food/create_food.html', {'form': form})
Beispiel #2
0
    def post(self, request):
        form = FoodForm(request.POST, request.FILES)

        if not form.is_valid():
            context = {"form": form}
            return render(request, self.template, context)

        Alimento.objects.create(
            nombre=form.cleaned_data["nombre"],
            descripcion=form.cleaned_data["descripcion"],
            precio=form.cleaned_data["precio"],
            foto=form.cleaned_data["foto"],
            categoria=form.cleaned_data["categoria"]
        )
        return redirect("/food/all")
Beispiel #3
0
def submit(request):
    """
    Displays the food submit form and handles the food creation action.
    Requires user to be logged in.
    """
    if request.method == 'POST':
        form = FoodForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/food/submitsuccess/')
    else:
        form = FoodForm()
    context = {'form': form}
    context.update(csrf(request))
    return render_to_response('submit.html', context,
                              context_instance=RequestContext(request))
Beispiel #4
0
def edit(request, foodslug):
    """
    Displays the food_item edit form and handles the food_item edit info action.
    Requires user to be logged in.
    """
    food_item = Food.objects.get(slug=foodslug)
    if request.method == 'POST':
        form = FoodForm(request.POST, request.FILES, instance=food_item)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(food_item.get_absolute_url())
    else:
        form = FoodForm(instance=food_item)
    context = {'form': form}
    context.update(csrf(request))
    return render_to_response('edit.html', context,
                              context_instance=RequestContext(request))
Beispiel #5
0
def search(request  ):
    if request.method == 'POST':
        name = request.POST['query']
        a = Food.objects.filter(user_id=request.user.id)
        form = FoodForm()
        b = predictfood(peak(name))
        return render(request, 'home.html',
                      {'user': request.user.username, 'form': form, 'food': a, 'detail': "",'rate':b})
Beispiel #6
0
def foods(request):
    if request.method == 'POST':
        name = request.POST['food_name']
        s = Food.objects.create(name=name , user=request.user)
        return redirect('home')
    else:
        form = FoodForm()
        a = Food.objects.filter(user_id = request.user.id)
        return render(request, 'food.html', {'form': form , 'food': a})
Beispiel #7
0
def restaurant_edit_meal(request, food_id):
    form = FoodForm(instance=Food.objects.get(id=food_id))
    if request.method == "POST":
        form = FoodForm(request.POST,
                        request.FILES,
                        instance=Food.objects.get(id=food_id))

        if form.is_valid():
            form.save()
            return redirect(restaurant_meal)
    return render(request, 'restaurant/edit_meal.html', {"form": form})
Beispiel #8
0
def index(request):
    add_food = FoodForm()
    if request.method == 'POST':
        new_food = FoodForm(request.POST)
        if new_food.is_valid():
            new_food.save(commit=True)
        else:
            print("ERROR FORM INVALID")
    return render(request, 'food/index.html', {'add_food': add_food})
Beispiel #9
0
def restaurant_add_meal(request):
    form = FoodForm()
    if request.method == "POST":
        form = FoodForm(request.POST, request.FILES)

        if form.is_valid():
            food = form.save(commit=False)
            food.restaurant = request.user.restaurant
            food.save()
            return redirect(restaurant_meal)
    return render(request, 'restaurant/add_meal.html', {"form": form})
Beispiel #10
0
 def get(self, request):
     """Render add artist form."""
     form = FoodForm()
     context = {"form": form}
     return render(request, self.template, context)
Beispiel #11
0
def particular_food(request ,id):
    a = Food.objects.get(id=id)
    s = Food.objects.filter(user_id=request.user.id)
    form = FoodForm()
    return render(request,'home.html',{'user':request.user.username ,'form': form ,'food':s ,'detail':process(a.name)  ,'rate':0})
Beispiel #12
0
def home(request ):
    a = Food.objects.filter(user_id=request.user.id)
    form = FoodForm()
    return render(request,'home.html',{'user':request.user.username ,'form': form ,'food':a,'detail':process('food') ,'rate':0})