Added Place edit function.

This commit is contained in:
Marcus Scholz 2020-07-29 21:28:12 +02:00
parent 6ef959d10b
commit 066bc6011a
2 changed files with 7 additions and 2 deletions

View File

@ -6,5 +6,6 @@ urlpatterns = [
path('signup/', SignUpView.as_view(), name='signup'),
path('place/<int:pk>/', place_detail_view, name='place_detail'),
path('place/create/', PlaceEditView.as_view(), name='place_create'),
path('place/edit/<int:pk>/', PlaceEditView.as_view(), name='place_edit'),
path('place/', place_list_view)
]

View File

@ -1,4 +1,4 @@
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse_lazy
from django.views.generic.edit import CreateView
from django.views import View
@ -24,7 +24,11 @@ def hello_world(request):
class PlaceEditView(View):
def get(self, request, *args, **kwargs):
place_form = PlaceForm()
if 'pk' in kwargs:
place = get_object_or_404(Place,pk=kwargs['pk'])
place_form = PlaceForm(instance=place)
else:
place_form = PlaceForm()
return render(request, 'create_place.html', {'form':place_form})
def post(self, request, *args, **kwargs):
place_form = PlaceForm(request.POST)