Skip to content

Instantly share code, notes, and snippets.

@0xPr0xy
Created February 13, 2012 13:01
Show Gist options
  • Save 0xPr0xy/1816784 to your computer and use it in GitHub Desktop.
Save 0xPr0xy/1816784 to your computer and use it in GitHub Desktop.
autoregister.py
def autoregister(*app_list):
from django.db.models import get_models, get_app
from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered
for app_name in app_list:
app_models = get_app(app_name)
for model in get_models(app_models):
try:
admin.site.register(model)
except AlreadyRegistered:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment