def edit(request, ad_id=1): ad = get_object_or_404(Ad, id=ad_id) if request.POST: form = AdForm(request.POST, instance=ad) if form.is_valid(): form.save() return redirect('/') else: form = AdForm(instance=ad) return render(request, 'ads/edit-ad.html', ({ 'form': form, 'ad': ad, }))
def create(request): if request.POST: form = AdForm(request.POST) if form.is_valid(): form.save() return redirect('/') else: form = AdForm args = {} args.update(csrf(request)) args['form'] = form return render(request, 'ads/create-ad.html', args)