- July 26, 2008
- -4 (after 6 ratings)
I recently converted a site with over 60 models to newforms admin. I like the seperation of the display from the defintion, but it does introduce quite a bit more typing which isn't in the spirit of Django DRY...
I particular I got bored of typing
Over and over again so I wrote this little bit of code which does a bit of introspection. It assumes that
- You import all your models into your admin.py, ie from "myapp.models import *"
- The admin class for Model is called ModelAdmin
Put this snippet at the end of your admin.py
I hope that saves someone a bit of typing!
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
- DRY Fieldsets by DrMeers 5 years, 9 months ago
- GeoDjango maps in admin TabularInlines by alanB 4 years, 5 months ago
- testdata tag for templates by showell 5 years, 10 months ago
- Generate newforms-admin admin.py file by NL 7 years, 1 month ago
- Admin action for a generic "CSV Export" by javinievas 4 years, 1 month ago