Compare commits

..

No commits in common. "bf0d20dbbd1f117fa4d9b9f3d6fbe086f545d80a" and "4e9f91616977214caf11e0839e445fee468335cd" have entirely different histories.

View File

@ -26,13 +26,11 @@ class PlaceEditView(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: if 'pk' in kwargs:
place = get_object_or_404(Place,pk=kwargs['pk']) place = get_object_or_404(Place,pk=kwargs['pk'])
place_form = PlaceForm(instance=place) place_form = PlaceForm(instance=place)
else: else:
place_form = PlaceForm() place_form = PlaceForm()
context = { context = {
'place_form': place_form, 'place_form': place_form,
'place_image_form': place_image_form 'place_image_form': place_image_form
@ -44,20 +42,22 @@ class PlaceEditView(View):
if place_form.is_valid(): if place_form.is_valid():
submitter = request.user submitter = request.user
place = place_form.save(commit=False) instance = place_form.save(commit=False)
# Save logged in user as "submitted_by" # Save logged in user as "submitted_by"
place.submitted_by = submitter instance.submitted_by = submitter
place.save() instance.save()
if request.FILES: if request.FILES:
self._apply_multipart_image_upload( for image in request.FILES.getlist('filename'):
request.FILES.getlist('filename'), place_image = PlaceImage.objects.create(
place, filename=image,
submitter place=instance,
submitted_by=submitter
) )
place_image.save()
kwargs_to_pass = { kwargs_to_pass = {
'pk': place.pk 'pk': instance.pk
} }
return redirect(reverse_lazy('place_detail', kwargs=kwargs_to_pass)) return redirect(reverse_lazy('place_detail', kwargs=kwargs_to_pass))
else: else:
@ -65,12 +65,3 @@ class PlaceEditView(View):
'form': form_place 'form': form_place
} }
return render(request, 'create_place.html', context) return render(request, 'create_place.html', context)
def _apply_multipart_image_upload(self, files, place, submitter):
for image in files:
place_image = PlaceImage.objects.create(
filename=image,
place=place,
submitted_by=submitter
)
place_image.save()