Compare commits
2 Commits
fc4167ffc2
...
81a9c756f6
Author | SHA1 | Date | |
---|---|---|---|
81a9c756f6 | |||
2fa4874c08 |
@ -22,11 +22,10 @@ class PlaceForm(forms.ModelForm):
|
|||||||
class PlaceImageCreateForm(forms.ModelForm):
|
class PlaceImageCreateForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PlaceImage
|
model = PlaceImage
|
||||||
fields = '__all__'
|
fields = ['filename']
|
||||||
exclude = ['submitted_by', 'place', 'description']
|
|
||||||
widgets = {
|
widgets = {
|
||||||
'filename': forms.ClearableFileInput(attrs={'multiple': True}),
|
'filename': forms.ClearableFileInput(attrs={'multiple': True})
|
||||||
},
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
15
lostplaces/lostplaces_app/templates/update_place.html
Normal file
15
lostplaces/lostplaces_app/templates/update_place.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends 'global.html'%}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
# {% block title %}Place erstellen{% endblock %}
|
||||||
|
|
||||||
|
{% block maincontent %}
|
||||||
|
|
||||||
|
<h2>Place aktualisieren</h2>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Abschicken</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock maincontent %}
|
@ -1,11 +1,18 @@
|
|||||||
from django.urls import path
|
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 = [
|
urlpatterns = [
|
||||||
path('hello_world/', hello_world), # You know what this is :P
|
path('hello_world/', hello_world), # You know what this is :P
|
||||||
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/', PlaceCreateView.as_view(), name='place_create'),
|
||||||
path('place/edit/<int:pk>/', PlaceEditView.as_view(), name='place_edit'),
|
path('place/update/<int:pk>/', PlaceUpdateView.as_view(), name='place_edit'),
|
||||||
path('place/', place_list_view, name='place_list')
|
path('place/', place_list_view, name='place_list')
|
||||||
]
|
]
|
@ -2,6 +2,9 @@ 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
|
||||||
|
from django.http import Http404
|
||||||
|
from django.views.generic.edit import UpdateView
|
||||||
|
|
||||||
|
|
||||||
from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm
|
from .forms import ExplorerCreationForm, PlaceForm, PlaceImageCreateForm
|
||||||
from .models import Place, PlaceImage
|
from .models import Place, PlaceImage
|
||||||
@ -22,15 +25,18 @@ def place_detail_view(request, pk):
|
|||||||
def hello_world(request):
|
def hello_world(request):
|
||||||
return render(request, 'hello_world.html', {'text':'Hello World!'})
|
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):
|
def get(self, request, *args, **kwargs):
|
||||||
place_image_form = PlaceImageCreateForm()
|
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 = {
|
context = {
|
||||||
@ -51,9 +57,9 @@ class PlaceEditView(View):
|
|||||||
|
|
||||||
if request.FILES:
|
if request.FILES:
|
||||||
self._apply_multipart_image_upload(
|
self._apply_multipart_image_upload(
|
||||||
request.FILES.getlist('filename'),
|
files=request.FILES.getlist('filename'),
|
||||||
place,
|
place=place,
|
||||||
submitter
|
submitter=submitter
|
||||||
)
|
)
|
||||||
|
|
||||||
kwargs_to_pass = {
|
kwargs_to_pass = {
|
||||||
@ -67,6 +73,7 @@ class PlaceEditView(View):
|
|||||||
return render(request, 'create_place.html', context)
|
return render(request, 'create_place.html', context)
|
||||||
|
|
||||||
def _apply_multipart_image_upload(self, files, place, submitter):
|
def _apply_multipart_image_upload(self, files, place, submitter):
|
||||||
|
print(files)
|
||||||
for image in files:
|
for image in files:
|
||||||
place_image = PlaceImage.objects.create(
|
place_image = PlaceImage.objects.create(
|
||||||
filename=image,
|
filename=image,
|
||||||
|
Loading…
Reference in New Issue
Block a user