How does one check to see if a modeladmin exists for a given model?
modeladmins are created by registering a model with the admin.site object. how can one check the site object to see which models have been registered, and with which admin_class?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Interesting question, which provoked me to do a little digging.
Once the admin classes have been registered, they are stored in an attribute of the
siteobject called – not surprisingly –_registry. This is a dictionary of model classes to modeladmin classes – note both the keys and values are classes, not names.So if you have an admin.py like this:
then once that has actually been imported – usually by the
admin.autodiscover()line in urls.py –admin.site._registrywill contain something like this:and you would get the ModelAdmin object for
MyModelby using the model itself as the key: