def order_by_rating(self,
                        aggregator=models.Sum,
                        descending=True,
                        queryset=None,
                        alias='score'):
        related_field = get_content_object_field(self.model)

        if queryset is None:
            queryset = self.rated_model._default_manager.all()

        if not is_gfk(related_field):
            ordering = descending and '-%s' % alias or alias
            query_name = related_field.related_query_name()

            if len(self.query.where.children):
                queryset = queryset.filter(
                    **{'%s__pk__in' % query_name: self.values_list('pk')})

            return queryset.annotate(
                **{
                    alias: aggregator('%s__score' % query_name)
                }).order_by(ordering)

        else:
            return generic_annotate(queryset, related_field,
                                    aggregator('score'), self, descending,
                                    alias)
    def order_by_rating(self, aggregator=models.Sum, descending=True,
                        queryset=None, alias='score'):
        related_field = get_content_object_field(self.model)

        if queryset is None:
            queryset = self.rated_model._default_manager.all()

        ordering = descending and '-%s' % alias or alias

        if not is_gfk(related_field):
            query_name = related_field.related_query_name()

            if len(self.query.where.children):
                queryset = queryset.filter(**{
                    '%s__pk__in' % query_name: self.values_list('pk')
                })

            return queryset.annotate(**{
                alias: aggregator('%s__score' % query_name)
            }).order_by(ordering)

        else:
            return generic_annotate(
                queryset,
                self,
                aggregator('score'),
                related_field,
                alias=alias
            ).order_by(ordering)
Exemple #3
0
 def generate_hash(self):
     content_field = get_content_object_field(self)
     if is_gfk(content_field):
         uniq = (getattr(self, content_field.ct_field).pk, long(getattr(self, content_field.fk_field)))
     else:
         uniq = getattr(self, content_field.name).pk
     hashed = sha_constructor(str(uniq)).hexdigest()
     return hashed
 def generate_hash(self):
     content_field = get_content_object_field(self)
     if is_gfk(content_field):
         uniq = (getattr(self, content_field.ct_field).pk,
                 long(getattr(self, content_field.fk_field)))
     else:
         uniq = getattr(self, content_field.name).pk
     hashed = sha_constructor(str(uniq)).hexdigest()
     return hashed
 def is_gfk(self):
     return is_gfk(self.get_content_object_field())
 def is_gfk(self):
     return is_gfk(self.get_content_object_field())