Type less with newforms admin

1
2
3
4
5
# Register Model with ModelAdmin
for name, model_admin in globals().copy().iteritems():
    if name.endswith("Admin"):
        model = globals()[name[:-5]]
        admin.site.register(model, model_admin)

More like this

  1. DRY Fieldsets by DrMeers 2 years, 11 months ago
  2. GeoDjango maps in admin TabularInlines by alanB 1 year, 7 months ago
  3. SSL Middleware for Webfaction by parlar 5 years ago
  4. testdata tag for templates by showell 3 years ago
  5. Active User Sorted ModelAdmin by daemondazz 2 years, 10 months ago

Comments

aarond10ster (on July 27, 2008):

Ummm...

class MyModel:
    ...
    class Admin:
         pass

Is this too hard to do? It does involve an extra 20 characters per model but gives you freedom to customise as needed later on and explicitly states whats going on.

#

jho406 (on July 30, 2008):

@aarond10ster

Your referring to old-forms admin. Django 1.0 alpha uses newforms-admin and has completely decoupled admin from the models.

#

alia_khouri (on September 2, 2008):

Thanks for that. I wrapped your code in a function. Please see [snippet 1015] (http://www.djangosnippets.org/snippets/1015/)

AK

#

(Forgotten your password?)