Thursday, July 17, 2014

Django admin - register all your models the quick and dirty way

Would you like to just import all your models and make them all available to your django admin interface? I would, and here's how I'm doing it now:
# app/admin.py
from django.contrib import admin

from . import models


for _, inst in models.__dict__.items():
    if isinstance(inst, type):
        try:
            admin.site.register(inst)
        except:
            pass
I needed the empty try/except block to avoid bugging out on the use of an AbstractUser model but for now, this works great.