Redirect to a new form in Django Admin on Save
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
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
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.