class GD_Update(UpdateView):
# setting the model, form_class and template_name
model = ImmoGrunddaten
form_class = form_immogrunddaten_anlegen
template_name = templ_folder_name + 'gd_update.html'
# what should happen if the updateview was successful
def get_success_url(self):
gdid = self.object.pk
return reverse_lazy(url_app_name + 'gd_ansehen', kwargs={'pk':gdid})
# I guess that I need this in order to get the data from the database and to populate the form
def get_object(self, queryset=None):
self.queryset = ImmoGrunddaten.objects.get(id = self.to_update)
return self.queryset
# Here is the handling of the post calls
def post(self, request, pk):
# this is when I did not push a button like "confirm update", meaning the first call of the view via post method
if not self.request.POST.get('action', False) == 'aktualisieren':
self.to_update = pk
self.object = self.get_object()
return super(GD_Update, self).post(request, pk)
else:
# and this is what happens if the confirm button was pushed. Now I want to save the changes to the database. But I don't know how.
context = {
'fehlermeldung': 'das update handling wurde noch nicht hinterlegt'
}
return render(request, templ_folder_name + 'fehlerseite.html', context)