Changes between Version 26 and Version 27 of NewformsHOWTO


Ignore:
Timestamp:
03/10/2008 12:25:21 PM (7 years ago)
Author:
Lllama <f.ingram.lists@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewformsHOWTO

    v26 v27  
    609609...
    610610}}}
     611
     612== Q: How can I change where I get sent after saving a new entry to the database? ==
     613
     614A: You'll need to override the save_add method in your ModelAdmin. In the example below I've got a link on one
     615model's change form which points to the add view of another and passes along the GET variable "rep_id".
     616In the overriden method I check for this and tweak the location field of the HTTPResponseRedirect. Overriding
     617save_add gives us the added advantage of having all validation etc performed beforehand for us.
     618
     619{{{
     620#!python
     621from django.utils.encoding import iri_to_uri
     622...
     623
     624    def save_add(self, request, model, form, formsets, post_url_continue):
     625        rep_id = request.GET.get("rep_id", None)
     626        if rep_id:
     627            result = super(IssueOptions, self).save_add(request, model, form, formsets, post_url_continue)
     628            result['Location'] = iri_to_uri("/issuesdb/reports/report/%s/" % rep_id)
     629            return result
     630        return super(IssueOptions, self).save_add(request, model, form, formsets, post_url_continue)
     631}}}
Back to Top