def update_view(request, object_id=None): tour = get_object_or_404(Tour, id=object_id) form = TourModelForm(request.POST or None, instance=tour) if form.is_valid(): instance= form.save(commit=False) instance.save() template = "update_view.html" context = { "object": tour, "form": form, } return render(request, template, context)
def create_view(request): form = TourModelForm(request.POST or None) if form.is_valid(): instance = form.save(commit=False) instance.slug = slugify(instance.title) instance.save() template = "create_view.html" context = { "form":form, } return render(request, template, context)