Skip to content

Instantly share code, notes, and snippets.

@micrypt
Created June 10, 2014 10:34
Show Gist options
  • Save micrypt/9eddb1d49f58abeb71b2 to your computer and use it in GitHub Desktop.
Save micrypt/9eddb1d49f58abeb71b2 to your computer and use it in GitHub Desktop.
# utils/admin.py
from django.contrib import admin
from django.db.models import get_models, get_app
def autodiscover(name, exclude=[]):
excluded = [ model.__name__ for model in exclude ]
current_app = name.replace('.admin', '')
for model in get_models(get_app(current_app)):
if model.__name__ not in excluded:
admin.site.register(model)
# accounts/admin.py
from utils.admin import autodiscover
from .models import Profile
autodiscover(__name__, exclude=[Profile])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment