I’m using http://keith-wood.name/countdown.html. Each ‘Event’ table in my database has a ‘date’ column. date = models.DateTimeField()
The datetimefield( {{ event.date }}) will return ‘Aug. 15, 2012, 12:23 p.m.‘.
The default plugin format is ‘dHMS’.
How do I get my django date to properly display within this jquery plugin? Or better yet. How do I turn my datetimefield into a:
{{ countdown_day }},
{{ countdown_hour }},
{{ countdown_min }},
{{ countdown_sec }} ?
SCRIPT:
(function(){
var eventDate = '{{ event.date }}';
$('#defaultCountdown').countdown({until: eventDate});
$('#removeCountdown').toggle(function() {
$(this).text('Re-attach');
$('#defaultCountdown').countdown('destroy');
},
function() {
$(this).text('Remove');
$('#defaultCountdown').countdown({until: eventDate});
});
})();
You can format a Python date into a Django template using the ‘date’ filter (documentation).
To turn the date into a javascript date, I use {{ countdown|date:”U” }} to get the unix timestamp. You can create a javascript date object from this as follows: