保存时重定向到 Django Admin 中的新表单
您好,我正在为我的公司创建一个故障单应用程序,我想将用户重定向到一个新表单,他将在其中指定他提供的诊断和解决方案。 我的管理员是 基本上,现在我的代码正在调用第一个表单,当创建的对象是新的或状态为打开时,它正在调用 ClosedForm 当我的状态为关闭时。
我想要的是,当用户将状态从打开更改为关闭并保存票证时,他会被重定向到 ClosedForm
谢谢
class TicketFormClosed(ModelForm):
class Meta:
model = Ticket
fields = ('status','call_sheet_number','diagnose','solution','call_attend_date',)
class TicketForm(ModelForm):
class Meta:
model = Ticket
exclude = ('call_sheet_number','diagnose','solution','call_attend_date',)
class TicketAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
form = super(TicketAdmin, self).get_form(request, obj, **kwargs)
if obj == None or obj.status=='Open':
form = TicketForm
else:
form = TicketFormClosed
return form
Hi I am creating a trouble ticket app for my company, and I want to redirect the user to a new form where he will specify the diagnose and solution he offered.
my admin is
Basically, Right now my code is calling the first form, when the obj created is new or the status is open and it is calling the ClosedForm when my status is closed.
What I want is that, when the user changes the status from Open to Closed and saves the ticekt, he is redirected to ClosedForm
Thanks
class TicketFormClosed(ModelForm):
class Meta:
model = Ticket
fields = ('status','call_sheet_number','diagnose','solution','call_attend_date',)
class TicketForm(ModelForm):
class Meta:
model = Ticket
exclude = ('call_sheet_number','diagnose','solution','call_attend_date',)
class TicketAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
form = super(TicketAdmin, self).get_form(request, obj, **kwargs)
if obj == None or obj.status=='Open':
form = TicketForm
else:
form = TicketFormClosed
return form
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 admin.ModelAdmin 的源代码。您将在那里找到用于重定向的可重写挂钩。
例如,在中搜索 HttpResponseRedirect
django/contrib/admin/options.py
您将看到默认流程正在播放。
Take a look at the source code for admin.ModelAdmin. You will find the overridable hooks for redirecting there.
for example, search for HttpResponseRedirect in
django/contrib/admin/options.py
and you'll see the default flow playing out.