def update(request, pk): data = {} data['db'] = Carros.objects.get(pk=pk) form = CarrosForm(request.POST or None, instance=data['db']) if form.is_valid(): form.save() return redirect('home')
def edit(request, pk): data = {} data['db'] = Carros.objects.get(pk=pk) data['form'] = CarrosForm(instance=data['db']) return render(request, 'form.html', data)
def form(request): data = {} data['form'] = CarrosForm() return render(request, 'form.html', data)
def create(request): form = CarrosForm(request.POST or None) if form.is_valid(): form.save() return redirect('home')
def create(request): form = CarrosForm(request.POST or None) #Dados vindos do formulário if form.is_valid(): # Se os dados forem validos form.save() # salvar no banco de dados return redirect('home')