- 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
- get_object_or_none by azwdevops 3 months, 2 weeks ago
- Mask sensitive data from logger by agusmakmun 5 months, 1 week ago
- Template tag - list punctuation for a list of items by shapiromatron 1 year, 7 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 7 months ago
- Serializer factory with Django Rest Framework by julio 2 years, 2 months 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.