- Author:
- adiq
- Posted:
- May 29, 2014
- Language:
- Python
- Version:
- Not specified
- 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
- csrf test by zukosdead 3 weeks, 2 days ago
- find even number by Rajeev529 9 months ago
- Form field with fixed value by roam 9 months, 3 weeks ago
- New Snippet! by Antoliny0919 10 months ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 1 year ago
Comments
Nice code, works in 1.7 Question, I want multiple dates to appear in the drop-down which will be retrieved via a MySQL query.
How can I pass the array of times here?
#
Please login first before commenting.