Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13361 - Made sure jQuery is always included in the admin chang…

…elist and changeform. Thanks to Carl Meyer for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12997 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c3dbe9d50991cd749491633787c529b101fa04be 1 parent 1ad9c36
Jannis Leidel authored April 19, 2010
5  django/contrib/admin/options.py
@@ -271,9 +271,10 @@ def urls(self):
271 271
     def _media(self):
272 272
         from django.conf import settings
273 273
 
274  
-        js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
  274
+        js = ['js/core.js', 'js/admin/RelatedObjectLookups.js',
  275
+              'js/jquery.min.js', 'js/jquery.init.js']
275 276
         if self.actions is not None:
276  
-            js.extend(['js/jquery.min.js', 'js/jquery.init.js', 'js/actions.min.js'])
  277
+            js.extend(['js/actions.min.js'])
277 278
         if self.prepopulated_fields:
278 279
             js.append('js/urlify.js')
279 280
             js.append('js/prepopulate.min.js')
8  docs/ref/contrib/admin/index.txt
@@ -938,6 +938,14 @@ on your ``ModelAdmin``::
938 938
 Keep in mind that this will be prepended with ``MEDIA_URL``. The same rules
939 939
 apply as :ref:`regular media definitions on forms <topics-forms-media>`.
940 940
 
  941
+Django admin Javascript makes use of the `jQuery`_ library. To avoid
  942
+conflict with user scripts, Django's jQuery is namespaced as
  943
+``django.jQuery``. If you want to use jQuery in your own admin
  944
+JavaScript without including a second copy, you can use the
  945
+``django.jQuery`` object on changelist and add/edit views.
  946
+
  947
+.. _jQuery: http://jquery.com
  948
+
941 949
 Adding custom validation to the admin
942 950
 -------------------------------------
943 951
 
8  tests/regressiontests/admin_views/tests.py
@@ -1386,6 +1386,14 @@ def test_model_without_action(self):
1386 1386
         self.assert_('action-checkbox-column' not in response.content,
1387 1387
             "Found unexpected action-checkbox-column class in response")
1388 1388
 
  1389
+    def test_model_without_action_still_has_jquery(self):
  1390
+        "Tests that a ModelAdmin without any actions still gets jQuery included in page"
  1391
+        response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
  1392
+        self.assertEquals(response.context["action_form"], None)
  1393
+        self.assert_('jquery.min.js' in response.content,
  1394
+            "jQuery missing from admin pages for model with no admin actions"
  1395
+        )
  1396
+
1389 1397
     def test_action_column_class(self):
1390 1398
         "Tests that the checkbox column class is present in the response"
1391 1399
         response = self.client.get('/test_admin/admin/admin_views/subscriber/')

0 notes on commit c3dbe9d

Please sign in to comment.
Something went wrong with that request. Please try again.