Last active
March 1, 2016 08:38
-
-
Save josefmonje/a048806430e075983fec to your computer and use it in GitHub Desktop.
Brute force registration of Django models to admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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