How can I set success_url
based on a parameter?
I really want to go back to where I came from, not some static place. In pseudo code:
url(r
Define get_absolute_url(self)
on your model. Example
class Poll(models.Model):
question = models.CharField(max_length=100)
slug = models.SlugField(max_length=50)
# etc ...
def get_absolute_url(self):
return reverse('poll', args=[self.slug])
If your PollUpdateView(UpdateView)
loads an instance of that model as object
, it will by default look for a get_absolute_url()
method to figure out where to redirect to after the POST
. Then
url(r'^polls/(?P\w+)/, UpdateView.as_view(
model=Poll, template_name='generic_form_popup.html'),
should do.