Hi

I want to modidy my view that is based on UpdateView and it should work 
when called via post method.

This is what I have so far and I am not sure if it makes sense or if it 
could be done in an easier way.

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)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4a53a5b7-1f0f-4176-adac-9bbcb251995c%40googlegroups.com.

Reply via email to