Login

Creating custom time entries in Django Date widget

Author:
adiq
Posted:
May 29, 2014
Language:
Python
Version:
Not specified
Tags:
time widget django-admin
Score:
0 (after 0 ratings)

jQuery code for making custom list on Admin page in DateTime widget. Create new js file in your static folder with this code.

To use add custom js to Admin page like this:

class NiceAdmin(admin.ModelAdmin):

    class Media:
        js = ('js/adminNice.js',)

This code will change all DateTime widgets on selected page.

 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
if (!$) {
    $ = django.jQuery;
}

function overrideTimeOptions() {

    $("ul.timelist").each(function(){

        entries = $(this).children("li");

        baseEntry = entries.first();
        baseHref = baseEntry.find("a").attr("href");

        entries.remove();

        newEntryHref = baseHref.replace(/Date\([^\)]*\)/g, "Date(1970,1,1,6,0,0,0)");
        newEntry = '<li><a href="'+ newEntryHref +'">06:00:00</a></li>';
        $(this).append(newEntry);

    });


}

setTimeout(function(){overrideTimeOptions()},500);

More like this

  1. Collapsed stacked inlines by Aneon 5 years, 12 months ago
  2. Dynamic tabular inlines with optional drag-n-drop sorting by Aneon 5 years, 12 months ago
  3. Datetime widget by pigletto 7 years, 8 months ago
  4. Widget for DateTime values on Geraldo Reports by marinho 6 years ago
  5. Custom Times for the Django Admin Time Widget by caa 3 years, 5 months ago

Comments

Please login first before commenting.