6

I would like to use the django contrib.admin pages to edit my models, but call individual change page from my own views, an then return there after user clicks "save".

Ideally this should happen by appending the return URL to the admin page's url (as in "...?_return_url=)

Any hints?

Ber
  • 40,356
  • 16
  • 72
  • 88

1 Answers1

13

django.contrib.admin.options.ModelAdmin objects have a response_change method which you can override in a subclass to determine the response which should be returned after an object has been successfully saved - you could override this to return an appropriate HttpResponseRedirect for the object which was just saved.

ronnefeldt
  • 2,083
  • 23
  • 24
Jonny Buchanan
  • 61,926
  • 17
  • 143
  • 150
  • This is an excellent hint. It also needs overriding of the change_view method and some costomized templates to get the target URL into the change view's page. Its a good thing this requires no change inside the admin code, just overrides in derived classes and templates. – Ber Oct 28 '08 at 19:04
  • Thanks alot for this, was really stuck until i read your answer! – Mark Ellul Jul 28 '09 at 09:09
  • I found this blog post helped me understand insin's answer: http://joshourisman.com/2008/10/27/modifying-django-admin-redirects-after-adding-changing-and-deleting/ – adonm Sep 28 '09 at 10:20