views:

38

answers:

1

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
A: 

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.

Klaas van Schelven