[Answer]-Dates with django tastypie and backbone

0👍

After debugging I realized that what was happening is that the model was being initalized like this:

house = new House()

Therefore, the created_at attribute was undefined.

I decided to use timeago.js to display the information. However, a workaround for this problem could be:

App.House = Backbone.Model.extend({
    url: function() {
        return API_URL + this.id;
    },
    created_at: function() {
        // further processing could be performed here
        // before returning. You might want to return a 
        // formatted string or something...
        return new Date(this.get('created_at'));

    },
});

1👍

You need to provide the date in a form Javascript likes:

new Date("Month dd, yyyy hh:mm:ss");
new Date("Month dd, yyyy");
new Date(yy,mm,dd,hh,mm,ss);
new Date(yy,mm,dd);
new Date(milliseconds);

Leave a comment