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)

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

AK

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.