Frontend admin date picker widget

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from django.conf import settings
from django.contrib.admin.widgets import AdminDateWidget

I18NJS_URL = getattr(settings, 'I18NJS_URL', "i18njs/")
class Date(AdminDateWidget):
    '''
    Wrapper for the AdminDateWidget with missing media. You also have to add:

        (r'^%s' % I18JS_URL, 'django.views.i18n.javascript_catalog')

    to your site's main urls.py.
    '''
    class Media:
        # JSs have to be included in right order, thus:
        extend = False
        js = ("/%s" % I18NJS_URL, settings.ADMIN_MEDIA_PREFIX + "js/core.js",) +\
            AdminDateWidget.Media.js

        # extract approriative content from below CSS if you prefer
        css = {
            'screen': (settings.ADMIN_MEDIA_PREFIX + 'css/forms.css',
                       settings.ADMIN_MEDIA_PREFIX + 'css/global.css',
                       settings.ADMIN_MEDIA_PREFIX + 'css/base.css',
                       ),
        }

More like this

  1. Random-image template tag by pbx 6 years, 2 months ago
  2. jQuery color picker model field by fneumann 4 years, 5 months ago
  3. GeoDjango maps in admin TabularInlines by alanB 2 years, 8 months ago
  4. collectmedia command: Copy or link media files from installed apps by exogen 4 years, 9 months ago
  5. Logging Middleware by Magus 5 years, 8 months ago

Comments

muhdazwa (on December 20, 2010):

I like this snippet. Thank you :)

#

nathan.duthoit (on January 1, 2011):

From stackoverflow, if you are using Django 1.2 or later, you need some additional code in your template to help the widgets find their media:

{% load adminmedia %} /* At the top of the template. */

/* In the head section of the template. */
<script type="text/javascript">
window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";
</script>

#

(Forgotten your password?)