[ACCEPTED]-is it possible to create a custom admin view without a model behind it-admin

Accepted answer
Score: 26

hmmm. Thanks for your help everyone. The 4 solution I have come up ( with your help 3 ofcourse :) is as follows:

I have two custom 2 templates:


Under views.py:

class MyModel(object):
    # ... Access other models
    # ... process / normalise data 
    # ... store data

def my_model_list_view(request) #show list of all objects
    #. . . create objects of MyModel . . .
    #. . . call their processing methods . . .
    #. . . store in context variable . . . 
    r = render_to_response('admin/myapp/my_model_list.html', context, RequestContext(request))
    return HttpResponse(r)

def my_model_detail_view(request, row_id) # Shows one row (all values in the object) in detail     
    #. . . create object of MyModel . . .
    #. . . call it's methods . . .
    #. . . store in context variable . . . 
    r = render_to_response('admin/myapp/my_model_detail.html', context, RequestContext(request))
    return HttpResponse(r)

Under the main 1 django urls.py:

urlpatterns = patterns( 
    (r'^admin/myapp/mymodel/$', my_model_list_view),
    (r'^admin/myapp/mymodel/(\d+)/$', my_model_detail_view),
    ( r'^admin/', include( admin.site.urls ) )
Score: 8

You can add your views directly to the AdminSite object, rather 7 than to any particular ModelAdmin subclass which you 6 then register.

The default AdminSite is accessed 5 via django.contrib.admin.site, which is what you call register and 4 autodiscover on. Instead of using this, you 3 could create your own subclass and add your own views to it, and 2 then register your models against that rather 1 than the default one.

Score: 5

The most straightforward answer is "no". As 32 the Django Book says, the admin is for "Trusted 31 users editing structured content," in this 30 case the structured content being models 29 arranged in hierarchies and configured through 28 settings.py. More importantly, if your 27 object doesn't completely duck-type to a 26 models.Model complete with expected relationships, the 25 admin will probably toss exceptions all 24 over the place.

However, as the mantra goes, "It's 23 just python." You can override any of the 22 pages in admin. Just create your own templates 21 in your project, and have them come first 20 in the template search. Also, by inheriting 19 admin/base.html, you maintain the look & feel 18 of the administration project.

Write your 17 administrative view and templates for this 16 object, just like any others, but making 15 sure to wrap the views in the is_staff decorator 14 to ensure that the views are protected from 13 access by unauthorized users. Put those 12 in the application, perhaps in admin/views.py, with 11 templates/admin/object_list.html and object_form.html.

Once 10 you have appropriate administrative tools 9 for these non-database objects, you can 8 then provide access to them through the 7 administration index page: You want to override 6 admin/index.html, and provide additional 5 project-specific items to the page as needed.

I 4 have done exactly this to provide administrative 3 access to third-party APIs that store our 2 data, such as the ConstantContact email 1 service, and it works pretty well.

More Related questions