Added Place edit function.
This commit is contained in:
parent
6ef959d10b
commit
066bc6011a
@ -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)
|
||||
]
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user