diff --git a/lostplaces/lostplaces_app/urls.py b/lostplaces/lostplaces_app/urls.py index baf9b1a..373a30f 100644 --- a/lostplaces/lostplaces_app/urls.py +++ b/lostplaces/lostplaces_app/urls.py @@ -6,5 +6,6 @@ urlpatterns = [ path('signup/', SignUpView.as_view(), name='signup'), path('place//', place_detail_view, name='place_detail'), path('place/create/', PlaceEditView.as_view(), name='place_create'), + path('place/edit//', PlaceEditView.as_view(), name='place_edit'), path('place/', place_list_view) ] \ No newline at end of file diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index 3ab95e8..19b165e 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -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)