lostplaces-backend/django_lostplaces/lostplaces/views/place_image_views.py

18 lines
643 B
Python
Raw Normal View History

from django.views import View
from django.shortcuts import get_object_or_404
from lostplaces.views.base_views import PlaceAssetCreateView
from lostplaces.models import PlaceImage, Place
class PlaceImageCreateView(PlaceAssetCreateView):
model = PlaceImage
fields = ['filename']
template_name = 'place_image/place_image_create.html'
success_message = 'Place Images submitted'
def post(self, request, place_id, *args, **kwargs):
place = get_object_or_404(Place, pk=place_id)
super().post(request, place_id)
self.object.place = place
self.object = self.request.user
self.object.save()