easy admin registration

 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. Alphabetic filter for admin by semente 3 years, 4 months ago
  2. Generic admin action export selected rows to excel by jordic 4 months, 1 week ago
  3. Global custom permissions (no model association) by miracle2k 4 years, 6 months ago
  4. Django 1.2 template tag {% IF %} with {% ELIF %} support by danilchenko 11 months, 3 weeks ago
  5. Private Context Decorator by acdha 2 years, 5 months ago

Comments

(Forgotten your password?)