Fixed #32031 -- Added model class for each model to AdminSite.each_context().
This commit is contained in:
parent
0456d3e427
commit
3733ae8957
|
@ -461,6 +461,7 @@ class AdminSite:
|
|||
|
||||
info = (app_label, model._meta.model_name)
|
||||
model_dict = {
|
||||
'model': model,
|
||||
'name': capfirst(model._meta.verbose_name_plural),
|
||||
'object_name': model._meta.object_name,
|
||||
'perms': perms,
|
||||
|
|
|
@ -3025,6 +3025,7 @@ Templates can override or extend base admin templates as described in
|
|||
|
||||
Each model is a dict with the following keys:
|
||||
|
||||
* ``model``: the model class
|
||||
* ``object_name``: class name of the model
|
||||
* ``name``: plural name of the model
|
||||
* ``perms``: a ``dict`` tracking ``add``, ``change``, ``delete``, and
|
||||
|
@ -3032,6 +3033,10 @@ Templates can override or extend base admin templates as described in
|
|||
* ``admin_url``: admin changelist URL for the model
|
||||
* ``add_url``: admin URL to add a new model instance
|
||||
|
||||
.. versionchanged:: 4.0
|
||||
|
||||
The ``model`` variable for each model was added.
|
||||
|
||||
.. method:: AdminSite.has_permission(request)
|
||||
|
||||
Returns ``True`` if the user for the given ``HttpRequest`` has permission
|
||||
|
|
|
@ -72,6 +72,9 @@ Minor features
|
|||
|
||||
* The navigation sidebar now has a quick filter toolbar.
|
||||
|
||||
* The new context variable ``model`` which contains the model class for each
|
||||
model is added to the :meth:`.AdminSite.each_context` method.
|
||||
|
||||
:mod:`django.contrib.admindocs`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -55,7 +55,9 @@ class SiteEachContextTest(TestCase):
|
|||
admin_views = apps[0]
|
||||
self.assertEqual(admin_views['app_label'], 'admin_views')
|
||||
self.assertEqual(len(admin_views['models']), 1)
|
||||
self.assertEqual(admin_views['models'][0]['object_name'], 'Article')
|
||||
article = admin_views['models'][0]
|
||||
self.assertEqual(article['object_name'], 'Article')
|
||||
self.assertEqual(article['model'], Article)
|
||||
|
||||
# auth.User
|
||||
auth = apps[1]
|
||||
|
@ -63,6 +65,7 @@ class SiteEachContextTest(TestCase):
|
|||
self.assertEqual(len(auth['models']), 1)
|
||||
user = auth['models'][0]
|
||||
self.assertEqual(user['object_name'], 'User')
|
||||
self.assertEqual(user['model'], User)
|
||||
|
||||
self.assertEqual(auth['app_url'], '/test_admin/admin/auth/')
|
||||
self.assertIs(auth['has_module_perms'], True)
|
||||
|
|
Loading…
Reference in New Issue