Skip to content

Instantly share code, notes, and snippets.

@josefmonje
Last active March 1, 2016 08:38
Show Gist options
  • Save josefmonje/a048806430e075983fec to your computer and use it in GitHub Desktop.
Save josefmonje/a048806430e075983fec to your computer and use it in GitHub Desktop.
Brute force registration of Django models to admin
from django.contrib import admin
from django.db.models import Model
from . import models
"""
Brute force registration of Django models to admin
exclude_models = models from 3rd party models, anything that gives errors :)
"""
exclude_models = [
]
model_list = dir(models)
for model in model_list:
if model not in exclude_models:
try:
if issubclass(eval("models." + model), Model):
admin.site.register(eval("models." + model))
except Exception, e:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment