Пример #1
0
def editDish(request,dish_id):
    data = {}
    data.update(csrf(request))
    editedDish = Dish.objects.get(pk=dish_id)
    if request.method == 'POST': #jak wyslano formularza
        form = AddDishForm(request.POST)
        if form.is_valid(): #jak wszystko okej
            #to pozmieniaj dane
            editedDish.name=form.cleaned_data['name']
            editedDish.prize=form.cleaned_data['prize']
            editedDish.information=form.cleaned_data['information']
            editedDish.save()
            #editedDish.information=editedDish.information[0:]
            #editedDish.save()
            data['information'] = 'Edytowano danie!'
            data['back']='../'
            return render_to_response('info.html',data)
    else:
        
        fdata = {'name' : editedDish.name, 'prize' : editedDish.prize,
                     'information' : editedDish.information}
        form = AddDishForm(fdata)
        data['form']=form
        data['dish']=editedDish
        data['user']=request.user;
        return render_to_response('editDish.html',data)
Пример #2
0
def addDish(request):
    data = {}
    data.update(csrf(request))
    if request.method == 'POST': #jak wyslano formularza
        form = AddDishForm(request.POST)
        if form.is_valid(): #jak wszystko okej
            newDish = Dish(name=request.POST['name'],
                           prize=request.POST['prize'],
                           information=request.POST['information'],
                           inscribeBy=request.user)
            newDish.save()
            #strona informacyjna
            data['information'] = 'Dodano danie!'
            data['back']='../'
            return render_to_response('info.html',data)
    else:
        form = AddDishForm()
        data['form']=form
        data['user']=request.user;
        return render_to_response('addDish.html',data)