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('signup/', SignUpView.as_view(), name='signup'),
|
||||||
path('place/<int:pk>/', place_detail_view, name='place_detail'),
|
path('place/<int:pk>/', place_detail_view, name='place_detail'),
|
||||||
path('place/create/', PlaceEditView.as_view(), name='place_create'),
|
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)
|
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.urls import reverse_lazy
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
from django.views import View
|
from django.views import View
|
||||||
@ -24,6 +24,10 @@ def hello_world(request):
|
|||||||
|
|
||||||
class PlaceEditView(View):
|
class PlaceEditView(View):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
if 'pk' in kwargs:
|
||||||
|
place = get_object_or_404(Place,pk=kwargs['pk'])
|
||||||
|
place_form = PlaceForm(instance=place)
|
||||||
|
else:
|
||||||
place_form = PlaceForm()
|
place_form = PlaceForm()
|
||||||
return render(request, 'create_place.html', {'form':place_form})
|
return render(request, 'create_place.html', {'form':place_form})
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user