Django - custom admin page not model related

I am using Django 1.7 with Mezzanine. I would like to have some page in the admin area where employees can call some actions (control commands, etc.) using buttons and other controls.

I would also like to avoid creating a new model or manually create a template and add a link to it (if possible).

What are the most common / cleanest ways to achieve this?

+3


source to share


2 answers


It's actually easier. Just before urlpatterns in urls.py patch the admin url like this:



def get_admin_urls(urls):
    def get_urls():
        my_urls =  patterns('',
           url(r'^$', YourCustomView,name='home'), 
        )
        return my_urls + urls
    return get_urls

admin.autodiscover()

admin_urls = get_admin_urls(admin.site.get_urls())
admin.site.get_urls = admin_urls

      

+3


source


ModelAdmin.get_urls

allows you to add a url to the admin address. So you can add your own view like this:

class MyModelAdmin(admin.ModelAdmin):
    def get_urls(self):
        urls = super(MyModelAdmin, self).get_urls()
        my_urls = patterns('',
            (r'^my_view/$', self.my_view)
        )
        return my_urls + urls

    def my_view(self, request):
        # custom view which should return an HttpResponse
        pass

      



https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls

I haven't tried this, but it seems to me that you can subclass the built-in admin view and let your custom template extend the built-in admin templates.

+1


source







All Articles