Esempio n. 1
0
def add(request):
    police_car_form = PoliceCarForm(
        data=request.POST or None
    )
    if police_car_form.is_valid():
        police_car_form.save(auth.get_user(request))
        messages.success(request, u"Material salvo com sucesso.")
        return redirect('police_car_list')
    
    template_context = {
        'police_car_form': police_car_form,
    }
    return render(
        request=request,
        template_name='police_car/add.html',
        dictionary=template_context
    )
Esempio n. 2
0
def edit(request, pk):
    police_car = get_object_or_404(
        klass=PoliceCar, 
        pk=pk
    )
    police_car_form = PoliceCarForm(
        data=request.POST or None,
        instance=police_car
    )
    if police_car_form.is_valid():
        police_car_form.save(auth.get_user(request))
        messages.success(request, u"Material editado com sucesso.")
        return redirect('police_car_list')

    template_context = {
        'police_car': police_car,
        'police_car_form': police_car_form,
    }
    return render(
        request=request,
        template_name='police_car/edit.html',
        dictionary=template_context
    )