Beispiel #1
0
    def resolve_into(self, queryset: "AwaitableQuery[MODEL]",
                     context: QueryContext):
        # So far as I can imagine, the annotation will be expanded
        # independently, we just refer to it here.
        _, field = context.resolve_field_name(self.field_name,
                                              queryset,
                                              accept_relation=False,
                                              expand_annotation=False)

        if not queryset.is_aggregate() or context.query._groupbys:
            context.query = context.query.orderby(field, order=self.direction)
Beispiel #2
0
    def create_query(self, parent_context: QueryContext) -> QueryBuilder:
        query = self.query_builder(
            parent_context.alias if parent_context else None)
        context = QueryContext(query, parent_context)
        context.push(self.model, query._from[-1])

        self._add_query_details(context=context)
        for return_as, field_name in self.fields_for_select.items():
            _, field = context.resolve_field_name(field_name,
                                                  self,
                                                  accept_relation=False)
            context.query._select_other(field.as_(return_as))

        context.pop()
        return context.query