Login

easy admin registration

Author:
alia_khouri
Posted:
September 2, 2008
Language:
Python
Version:
.96
Tags:
admin register
Score:
-1 (after 1 ratings)

This essentially wraps snippet 917 (with full credit to author ncw) in a convenience function so that you can type:

admin_register(admin, namespace=globals())

or more concisely:

admin_register(admin, globals())

at the end of your admin.py file without having to register each model and admin class individually.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def admin_register(admin, namespace):
    '''convenience function to easily register admin classes
    
    :param admin: result of 'from django.contrib import admin'
    :param namespace: must take a locally called globals

    usage::
        
        # should be at the end of the admin.py file  
        # globals must be called locally as below
        admin_register(admin, namespace=globals())
    
    '''
    for name, model_admin in namespace.copy().iteritems():
        if name.endswith("Admin"):
            model = namespace[name[:-5]]
            admin.site.register(model, model_admin)

More like this

  1. One register on admin by zodman 3 years, 1 month ago
  2. Alphabetic filter for admin by semente 6 years, 7 months ago
  3. Django 1.2 template tag {% IF %} with {% ELIF %} support by danilchenko 4 years, 2 months ago
  4. Generic admin action export selected rows to excel by jordic 3 years, 6 months ago
  5. GeoDjango maps in admin TabularInlines by alanB 4 years, 6 months ago

Comments

Please login first before commenting.