I wrote a notification app using swampdragon. Unfortunately, pub_date variable includes microseconds which I don't want it to be there. How can I format it like 'dd-MM-yyyy HH:mm:ss' or like in the admin site(a.m p.m version)? My controller.js:
var AnnounceControllers = angular.module('AnnounceControllers', []);
AnnounceControllers.controller('AnnounceListCtrl', ['$scope', '$dragon', function ($scope, $dragon) {
$scope.announceList = {};
$scope.announcements = [];
$scope.channel = 'announce';
$dragon.onReady(function() {
$dragon.subscribe('announcements', $scope.channel, {announce_list__id: 1}).then(function(response) {
$scope.dataMapper = new DataMapper(response.data);
});
$dragon.getSingle('announce-list', {id:1}).then(function(response) {
$scope.announceList = response.data;
});
$dragon.getList('announcements', {list_id:1}).then(function(response) {
$scope.announcements = response.data;
});
});
$dragon.onChannelMessage(function(channels, message) {
if (indexOf.call(channels, $scope.channel) > -1) {
$scope.$apply(function() {
$scope.dataMapper.mapData($scope.announcements, message);
});
}
});
}]);
My app.js:
var AnnounceApp = angular.module('AnnounceApp', [
'SwampDragonServices',
'AnnounceControllers'
]);
In HTML :
<h3 ng-repeat="item in announcements">
<div class="alert alert-info" role="alert">
{{ item.content }} {{item.pub_date| date:'dd-MM-yyyy HH:mm:ss'}}
<br>
</div>
</h3>
models.py:
pub_date = models.DateTimeField(auto_now_add = True)
serializers.py:
class AnnounceSerializer(ModelSerializer):
class Meta:
model = "post.Announce"
publish_fields = ("content","pub_date")
I used some info from Daniel Cottone and did those:
isoformat without parameters worked for me.