Login

Custom Times for the Django Admin Time Widget

Author:
caa
Posted:
November 19, 2011
Language:
HTML/template
Version:
1.3
Tags:
template javascript
Score:
0 (after 0 ratings)

Based on code from mihelac.org

Modified to work in Django 1.3.1. Put it in templates/admin/app_label/model/change_form.html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{% extends "admin/change_form.html" %}

{% block extrahead %}{{ block.super }}
<script type="text/javascript">
django.jQuery(window).load(function() {
    django.jQuery('.timelist').each(function(num, el) {
        time_format = get_format('TIME_INPUT_FORMATS')[0];
        django.jQuery(el).html('');
        for (i=8; i<20; i++) {
          var time = new Date(1970,1,1,i,0,0);
          lnk = "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '" + time.strftime(time_format) + "');"
          /*django.jQuery(el).append('<li><a href="'lnk'">' + time.strftime('%H:%M') + '</a></li>');*/
          django.jQuery(el).append('<li><a href="' + lnk + '">' + time.strftime(time_format) + '</a></li>');
        }

    });
});
</script>
{% endblock %}

More like this

  1. Creating custom time entries in Django Date widget by adiq 11 months ago
  2. Hidden Date Display Widget for Admin by andrew.schoen 5 years, 9 months ago
  3. Admin Image Widget + easy-thumbnails by babu 3 years, 10 months ago
  4. Custom admin widgets by field type by dgouldin 6 years, 1 month ago
  5. Custom CheckboxSelectMultiple by martync 5 years, 6 months ago

Comments

Please login first before commenting.