Abhilash Nanda
Abhilash Nanda

Reputation: 359

Extending Django Admin View not working

Below is the code to extend the ModelAdmin and use our own page. However, regex is not getting accepted. Below further is given the list of regex that the matched, but the one that I try to extend is not getting used and thus not in the list. Can anyone please help???

class EmployeePayslipAdmin(admin.ModelAdmin):
    """docstring for PayslipAdmin"""
    def get_urls(self):
        from django.conf.urls.defaults import patterns, url
        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        info = self.model._meta.app_label, self.model._meta.module_name

        urls = super(EmployeePayslipAdmin, self).get_urls()
        my_urls = patterns('',
            url(
                r'/HRMS/mos/employeepayslip/',
                wrap(self.employee_view),
                name='%s_%s_payslip' % info),
        )
        print info
        return my_urls + urls

    def employee_view(self,request, id):
        print "working"
        return render_to_response(
            'mytemplate.html',
            {'list' : Employee.objects.all()},
                 RequestContext(request,{}),
        )

This code is somehow not working. Am trying to use that URL, but django is not accepting it. It gives the list of URL it accesses and the above one is not one of them.

Using the URLconf defined in NGOMgt.urls, Django tried these URL patterns, in this order:
^admin/ ^$ [name='index']
^admin/ ^logout/$ [name='logout']
^admin/ ^password_change/$ [name='password_change']
^admin/ ^password_change/done/$ [name='password_change_done']
^admin/ ^jsi18n/$ [name='jsi18n']
^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$ [name='view_on_site']
^admin/ ^(?P<app_label>\w+)/$ [name='app_list']
^admin/ ^Accounts/recievefund/
^admin/ ^Accounts/payfund/
^admin/ ^auth/group/
^admin/ ^HRMS/employee/
^admin/ ^Project/project/
^admin/ ^Accounts/paymenthead/
^admin/ ^Project/projectprogress/
^admin/ ^HRMS/employeepayslip/
^admin/ ^auth/user/
^admin/ ^Accounts/incomehead/
^admin/ ^sites/site/
^admin/ ^HRMS/payslip/
^grappelli/

What might be wrong???

Upvotes: 0

Views: 283

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599600

See the note box in the get_urls docs, which states that URLs there are included under the URL for the admin. So, assuming your app is HRMS and your model is EmployeePaySlip, that URL will be /admin/HRMS/employeepayslip/HRMS/mos/employeepayslip/, which probably isn't what you want.

Upvotes: 2

Related Questions