Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.views import generic
- from .forms import PlaceCreateForm
- from .models import Place
- class PlaceCreateView(generic.CreateView):
- form_class = PlaceCreateForm
- model = Place
- template_name = 'destination/place_form.html'
- success_url = reverse_lazy('travelogue_view')
- def form_valid(self, form):
- place = form.save(commit=False)
- place.user = self.request.user
- # Check if a file was uploaded
- if 'photo' in self.request.FILES:
- place.photo = self.request.FILES['photo']
- place.save()
- return super().form_valid(form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement