如何在保存时将用户重定向到不同的应用程序?
我有两个应用程序,比如说app1
and app2
。如果用户单击“保存在”app2
那么它应该被重定向到app1
而不是默认页面。
我不想做自定义表单。
要在管理中保存后更改重定向目的地,您需要覆盖response_add()
(用于添加新实例)和response_change()
(用于更改现有的)ModelAdmin
class.
原始代码见django.contrib.admin.options
.
快速示例可以更清楚地说明如何执行此操作(将在 ModelAdmin 类中):
from django.core.urlresolvers import reverse
def response_add(self, request, obj, post_url_continue=None):
"""
This makes the response after adding go to another
app's changelist for some model
"""
return HttpResponseRedirect(
reverse("admin:otherappname_modelname_changelist")
)
def response_change(self, request, obj, post_url_continue=None):
"""
This makes the response go to the newly created
model's change page without using reverse
"""
return HttpResponseRedirect("../%s" % obj.id)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)