保存时重定向到 Django Admin 中的新表单

发布于 2024-09-08 16:43:26 字数 858 浏览 3 评论 0原文

您好,我正在为我的公司创建一个故障单应用程序,我想将用户重定向到一个新表单,他将在其中指定他提供的诊断和解决方案。 我的管理员是 基本上,现在我的代码正在调用第一个表单,当创建的对象是新的或状态为打开时,它正在调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奈何桥上唱咆哮 2024-09-15 16:43:26

查看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文