psqlextra/query.py
def add_fields(self, field_names: List[str], allow_m2m: bool=True) -> bool:
        """
        Adds the given (model) fields to the select set. The field names are
        added in the order specified.

        This overrides the base class's add_fields method. This is called by
        the .values() or .values_list() method of the query set. It instructs
        the ORM to only select certain values. A lot of processing is neccesarry
        because it can be used to easily do joins. For example, `my_fk__name` pulls
        in the `name` field in foreign key `my_fk`.

        In our case, we want to be able to do `title__en`, where `title` is a HStoreField
        and `en` a key. This doesn't really involve a join. We iterate over the specified
        field names and filter out the ones that refer to HStoreField and compile it into
        an expression which is added to the list of to be selected fields using `self.add_select`.
        """

        alias = self.get_initial_alias()
        opts = self.get_meta()
        cols = []
        for name in field_names:
            parts = name.split(LOOKUP_SEP)

            # it cannot be a special hstore thing if there's no __ in it
            if len(parts) > 1:
                column_name, hstore_key = parts[:2]
                is_hstore, field = self._is_hstore_field(column_name)
                if is_hstore:
                    cols.append(
                        HStoreColumn(self.model._meta.db_table or self.model.name, field, hstore_key)
                    )
                    continue

            join_info = self.setup_joins(parts, opts, alias, allow_many=allow_m2m)
            targets, final_alias, joins = self.trim_joins(
                join_info[1], join_info[3], join_info[4]
            )

            for target in targets:
                cols.append(target.get_col(final_alias))
        if cols:
            self.set_select(cols)
def add_fields(self, field_names: List[str], allow_m2m: bool=True) -> bool:
        """
        Adds the given (model) fields to the select set. The field names are
        added in the order specified.

        This overrides the base class's add_fields method. This is called by
        the .values() or .values_list() method of the query set. It instructs
        the ORM to only select certain values. A lot of processing is neccesarry
        because it can be used to easily do joins. For example, `my_fk__name` pulls
        in the `name` field in foreign key `my_fk`.

        In our case, we want to be able to do `title__en`, where `title` is a HStoreField
        and `en` a key. This doesn't really involve a join. We iterate over the specified
        field names and filter out the ones that refer to HStoreField and compile it into
        an expression which is added to the list of to be selected fields using `self.add_select`.
        """

        alias = self.get_initial_alias()
        opts = self.get_meta()
        cols = []
        for name in field_names:
            parts = name.split(LOOKUP_SEP)

            # it cannot be a special hstore thing if there's no __ in it
            if len(parts) > 1:
                column_name, hstore_key = parts[:2]
                is_hstore, field = self._is_hstore_field(column_name)
                if is_hstore:
                    cols.append(
                        HStoreColumn(self.model._meta.db_table or self.model.name, field, hstore_key)
                    )
                    continue

            join_info = self.setup_joins(parts, opts, alias, allow_many=allow_m2m)
            targets, final_alias, joins = self.trim_joins(
                join_info[1], join_info[3], join_info[4]
            )

            for target in targets:
                cols.append(target.get_col(final_alias))
        if cols:
            self.set_select(cols)
def add_fields ( self , field_names : List [ str ] , allow_m2m : bool = True ) -> bool : alias = self . get_initial_alias ( ) opts = self . get_meta ( ) cols = [ ] for name in field_names : parts = name . split ( LOOKUP_SEP ) # it cannot be a special hstore thing if there's no __ in it if len ( parts ) > 1 : column_name , hstore_key = parts [ : 2 ] is_hstore , field = self . _is_hstore_field ( column_name ) if is_hstore : cols . append ( HStoreColumn ( self . model . _meta . db_table or self . model . name , field , hstore_key ) ) continue join_info = self . setup_joins ( parts , opts , alias , allow_many = allow_m2m ) targets , final_alias , joins = self . trim_joins ( join_info [ 1 ] , join_info [ 3 ] , join_info [ 4 ] ) for target in targets : cols . append ( target . get_col ( final_alias ) ) if cols : self . set_select ( cols )
Adds the given (model) fields to the select set. The field names are
        added in the order specified.

        This overrides the base class's add_fields method. This is called by
        the .values() or .values_list() method of the query set. It instructs
        the ORM to only select certain values. A lot of processing is neccesarry
        because it can be used to easily do joins. For example, `my_fk__name` pulls
        in the `name` field in foreign key `my_fk`.

        In our case, we want to be able to do `title__en`, where `title` is a HStoreField
        and `en` a key. This doesn't really involve a join. We iterate over the specified
        field names and filter out the ones that refer to HStoreField and compile it into
        an expression which is added to the list of to be selected fields using `self.add_select`.
Adds the given ( model ) fields to the select set . The field names are added in the order specified .