just change:from django.contrib import adminfrom models import *import modelsimport inspectfrom django.db.models.base import ModelBasefrom django.contrib.admin.sites import AlreadyRegisteredfor name, obj in inspect.getmembers(models ):if inspect.isclass(obj):if isinstance(obj, ModelBase):if not obj._meta.abstract:try:admin.site.register(obj)except AlreadyRegistered:pass
Django admin register all models in admin interface
Normally it is really annoying, that you have to name all the models that you want to add to your admin site in Django in admin.py So I just wrote a little script that imports all of them. With some checks. You just need to edit the imports and you will have all the models in your admin front-end.
and you are ready to go :)
from models import *
import models
and
inspect.getmembers(models )
Subscribe to:
Posts (Atom)