S
S
Stanislav Fateev2015-07-07 19:11:18
Django
Stanislav Fateev, 2015-07-07 19:11:18

Django. get_success_url. Why so, and not otherwise?

In ModelFormMixin, which is used by BaseUpdateView, in the get_success_url() method url = self.object.get_absolute_url()
, we do not need to set success_url = reverse_lazy('blablabla') in the view, but define get_absolute_url() in the model.
In contrast, the DeletionMixin that is used by BaseDeleteView does not do this, it just needs the success_url.
Why is that? Why not make them the same? I had to override get_success_url for my DeleteView to do what I want.
Or am I somehow not working correctly with success_url in the view? I need to calculate url by ForeignKey, I do something like this:

model Child(models.Model):
    parent = models.ForeignKey(Parent)
    def get_absolute_url(self):
        return reverse('parent-detail', kwargs={'pk':str(self.parent.pk)})

How can I do the same in success_url? I can't write self.parent.pk there.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-07-07
@deliro

Obviously, because after the DeleteView has worked, the object will be deleted and it makes no sense for it to receive the get_absolute_url of the remote object, and it will not work to get it.
PS I don't know what structure you have there, but why are you getting the URL of the parent in the child?

V
Vladimir Abramov, 2015-07-07
@kivsiak

Well, what is not clear? After removal to you somewhere the user should be sent. In the absence of a model, only you can decide exactly where.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question