diff --git a/lostplaces/lostplaces_app/forms.py b/lostplaces/lostplaces_app/forms.py
index e3d61f6..e81601c 100644
--- a/lostplaces/lostplaces_app/forms.py
+++ b/lostplaces/lostplaces_app/forms.py
@@ -22,8 +22,7 @@ class PlaceForm(forms.ModelForm):
class PlaceImageCreateForm(forms.ModelForm):
class Meta:
model = PlaceImage
- fields = '__all__'
- exclude = ['submitted_by', 'place', 'description']
+ fields = ['filename']
widgets = {
'filename': forms.ClearableFileInput(attrs={'multiple': True})
}
diff --git a/lostplaces/lostplaces_app/templates/update_place.html b/lostplaces/lostplaces_app/templates/update_place.html
new file mode 100644
index 0000000..618cb22
--- /dev/null
+++ b/lostplaces/lostplaces_app/templates/update_place.html
@@ -0,0 +1,15 @@
+{% extends 'global.html'%}
+{% load static %}
+
+# {% block title %}Place erstellen{% endblock %}
+
+{% block maincontent %}
+
+
Place aktualisieren
+
+
+{% endblock maincontent %}
\ No newline at end of file
diff --git a/lostplaces/lostplaces_app/urls.py b/lostplaces/lostplaces_app/urls.py
index 663a9f1..08e20a9 100644
--- a/lostplaces/lostplaces_app/urls.py
+++ b/lostplaces/lostplaces_app/urls.py
@@ -1,11 +1,18 @@
from django.urls import path
-from .views import hello_world, place_detail_view, place_list_view, SignUpView, PlaceEditView
+from .views import (
+ hello_world,
+ place_detail_view,
+ place_list_view,
+ SignUpView,
+ PlaceCreateView,
+ PlaceUpdateView
+)
urlpatterns = [
path('hello_world/', hello_world), # You know what this is :P
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/create/', PlaceCreateView.as_view(), name='place_create'),
+ path('place/update//', PlaceUpdateView.as_view(), name='place_edit'),
path('place/', place_list_view, name='place_list')
]
\ No newline at end of file
diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py
index 2bb5685..6b31ed5 100644
--- a/lostplaces/lostplaces_app/views.py
+++ b/lostplaces/lostplaces_app/views.py
@@ -2,6 +2,9 @@ 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
+from django.http import Http404
+from django.views.generic.edit import UpdateView
+
from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm
from .models import Place, PlaceImage
@@ -22,16 +25,19 @@ def place_detail_view(request, pk):
def hello_world(request):
return render(request, 'hello_world.html', {'text':'Hello World!'})
-class PlaceEditView(View):
+class PlaceUpdateView(UpdateView):
+ template_name = 'update_place.html'
+ model = Place
+ form_class = PlaceForm
+
+ def get_success_url(self):
+ return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk})
+
+class PlaceCreateView(View):
def get(self, request, *args, **kwargs):
place_image_form = PlaceImageCreateForm()
-
- 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()
context = {
'place_form': place_form,