def get_ordering(self, request=None, queryset=None):
        if queryset is None:
            # with Django < 1.4 get_ordering works without fixes for mongoengine 
            return super(DocumentChangeList, self).get_ordering()

        params = self.params
        ordering = list(self.model_admin.get_ordering(request)
                        or self._get_default_ordering())
        if ORDER_VAR in params:
            # Clear ordering and used params
            ordering = []
            order_params = params[ORDER_VAR].split('.')
            for p in order_params:
                try:
                    none, pfx, idx = p.rpartition('-')
                    field_name = self.list_display[int(idx)]
                    order_field = self.get_ordering_field(field_name)
                    if not order_field:
                        continue # No 'admin_order_field', skip it
                    ordering.append(pfx + order_field)
                except (IndexError, ValueError):
                    continue # Invalid ordering specified, skip it.

        # Add the given query's ordering fields, if any.
        sign = lambda t: t[1] > 0 and '+' or '-'
        qs_ordering = [sign(t) + t[0] for t in queryset._ordering]
        ordering.extend(qs_ordering)

        # Ensure that the primary key is systematically present in the list of
        # ordering fields so we can guarantee a deterministic order across all
        # database backends.
        pk_name = self.lookup_opts.pk.name
        if not (set(ordering) & set(['pk', '-pk', pk_name, '-' + pk_name])):
            # The two sets do not intersect, meaning the pk isn't present. So
            # we add it.
            ordering.append('pk')
        return ordering
Compute the message to a parent.
dataset/ETHPy150Open MongoEngine/django-mongoengine/django_mongoengine/mongo_admin/views.py/DocumentChangeList.get_ordering--crossover with--dataset/ETHPy150Open bayespy/bayespy/bayespy/inference/vmp/nodes/bernoulli.py/CategoricalToBernoulli._compute_message_to_parent