Hi!
I have several objects in the database. Url to edit an object using the generic view looks like site.com/cases/edit/123/
where 123
is an id of the particular object. Consider the cases/url.py
contents:
url(r'edit/(?P<object_id>\d{1,5})/$', update_object, { ... 'post_save_redirect': ???}, name = 'cases_edit'),
where update_object
is a generic view. How to construct the post_save_redirect
to point to site.com/cases/edit/123/
. My problem is, that I don't know how to pass the id
of the object to redirect function. I tried something like:
'post_save_redirect': 'edit/(?P<object_id>\d{1,5})/'
'post_save_redirect': 'edit/' + str(object_id) + '/'
but obviously none of these work. reverse
function was suggested, but how to pass the particular id
?
'post_save_redirect': reverse('cases_edit', kwargs = {'object_id': ???})
{% url %}
in the temple also requires passing the id
of the particular object. The id
can be passed via extra_context
:
extra_context = {'object_id': ???}
In all the cases the problem is to get object_id
from the url.
regards
chriss