def object_new(request): if request.method == "POST": o = ObjectForm(request.POST) if o.is_valid(): o = o.save(commit=False) o.owner = request.user o.published_date = timezone.now() o.save() return redirect('object.views.object_list') else: o = ObjectForm() return render(request, 'object/edit.html', {'object': o})
def object_edit(request, pk): o = get_object_or_404(Object, pk=pk) if request.method == "POST": o = ObjectForm(request.POST, instance=o) if o.is_valid(): o = o.save(commit=False) o.owner = request.user o.published_date = timezone.now() o.save() return redirect('object.views.object_view', pk=o.pk) else: o = ObjectForm(instance=o) return render(request, 'object/edit.html', {'object': o})