Login

Custom Times for the Django Admin Time Widget

Author:
caa
Posted:
November 19, 2011
Language:
HTML/template
Version:
1.3
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. Bootstrap Accordian by Netplay4 5 years, 11 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 8 years, 11 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 8 years, 11 months ago
  4. Reusable form template with generic view by roldandvg 9 years ago
  5. Pagination Django with Boostrap by guilegarcia 9 years, 1 month ago

Comments

aaeronn (on April 27, 2016):

Everything works for me except when I click the date from dopdown It does not fill the input field.. It gives some weired value like NaNaNa something like this..

How to solve this ??

#

Please login first before commenting.