swampdragon objects not ordering properly

57 views Asked by At

I have a real time app, and this app provides me announcements from admin-site. Unfortunately, I could not handle the ordering issue which is new info must be on the top of the list. My app gives me the bottom of the list. After refreshing it fixes the list but I do not want to refresh for all new infos. before refresh:

  • afas 2015-07-21 12:07:10
  • 5 min 2015-07-21 12:07:03
  • 5 min 2015-07-21 12:27:16

after refresh:

  • 5 min 2015-07-21 12:27:16
  • afas 2015-07-21 12:07:10
  • 5 min 2015-07-21 12:07:03

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);
        });
    }
});
}]);

routers.py:

from swampdragon import route_handler
from swampdragon.route_handler import ModelRouter
from post.models import AnnounceList, Announce
from post.serializers import AnnounceListSerializer, AnnounceSerializer


class AnnounceListRouter(ModelRouter):
    route_name = 'announce-list'
    serializer_class = AnnounceListSerializer
    model = AnnounceList

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


class AnnounceRouter(ModelRouter):
    route_name = 'announcements'
    serializer_class = AnnounceSerializer
    model = Announce

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return  self.model.objects.filter(announce_list__id=kwargs['list_id']).order_by("-pub_date")


route_handler.register(AnnounceListRouter)
route_handler.register(AnnounceRouter)
1

There are 1 answers

0
kings856 On

In HTML:

<h3 ng-repeat="item in announcements | orderBy: '-date'">

I managed to order with orderBy filter