Compare commits
No commits in common. "bf0d20dbbd1f117fa4d9b9f3d6fbe086f545d80a" and "4e9f91616977214caf11e0839e445fee468335cd" have entirely different histories.
bf0d20dbbd
...
4e9f916169
@ -26,13 +26,11 @@ class PlaceEditView(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()
|
||||
|
||||
context = {
|
||||
'place_form': place_form,
|
||||
'place_image_form': place_image_form
|
||||
@ -44,20 +42,22 @@ class PlaceEditView(View):
|
||||
|
||||
if place_form.is_valid():
|
||||
submitter = request.user
|
||||
place = place_form.save(commit=False)
|
||||
instance = place_form.save(commit=False)
|
||||
# Save logged in user as "submitted_by"
|
||||
place.submitted_by = submitter
|
||||
place.save()
|
||||
instance.submitted_by = submitter
|
||||
instance.save()
|
||||
|
||||
if request.FILES:
|
||||
self._apply_multipart_image_upload(
|
||||
request.FILES.getlist('filename'),
|
||||
place,
|
||||
submitter
|
||||
)
|
||||
for image in request.FILES.getlist('filename'):
|
||||
place_image = PlaceImage.objects.create(
|
||||
filename=image,
|
||||
place=instance,
|
||||
submitted_by=submitter
|
||||
)
|
||||
place_image.save()
|
||||
|
||||
kwargs_to_pass = {
|
||||
'pk': place.pk
|
||||
'pk': instance.pk
|
||||
}
|
||||
return redirect(reverse_lazy('place_detail', kwargs=kwargs_to_pass))
|
||||
else:
|
||||
@ -65,12 +65,3 @@ class PlaceEditView(View):
|
||||
'form': form_place
|
||||
}
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user