21๐
โ
You can access admin.site._registry
dict of Model->ModelAdmin:
>>> ./manage.py shell
In [1]: from urls import * # load admin
In [2]: from django.contrib import admin
In [3]: admin.site._registry
Out[3]:
{django.contrib.auth.models.Group: <django.contrib.auth.admin.GroupAdmin at 0x22629d0>,
django.contrib.auth.models.User: <django.contrib.auth.admin.UserAdmin at 0x2262a10>,
django.contrib.sites.models.Site: <django.contrib.sites.admin.SiteAdmin at 0x2262c90>,
testapp.models.Up: <django.contrib.admin.options.ModelAdmin at 0x2269c10>,
nashvegas.models.Migration: <nashvegas.admin.MigrationAdmin at 0x2262ad0>}
This is what the admin index view does:
@never_cache
def index(self, request, extra_context=None):
"""
Displays the main admin index page, which lists all of the installed
apps that have been registered in this site.
"""
app_dict = {}
user = request.user
for model, model_admin in self._registry.items():
# ...
Note that variables prefixed with an underscore are potentially subject to changes in future versions of django.
๐คjpic
0๐
You can do something like this:
from django.apps import apps
models = apps.get_models()
for model in models:
try:
my_custom_admin_site.register(model)
except admin.sites.AlreadyRegistered:
pass
apps.get_models()
will give all the registered models in the default Django Admin site.
๐คJay Patel
- Python โ pyodbc call stored procedure with parameter name
- <django.db.models.fields.related.RelatedManager object at 0x7ff4e003d1d0> is not JSON serializable
- What is the correct way to deal with DB migration while using South, Django and Git?
- DeleteView with a dynamic success_url dependent on id
- Filter on django-import-export
Source:stackexchange.com