psqlextra/manager/manager.py
def insert_and_get(self, **fields):
        """Creates a new record in the database and then gets
        the entire row.

        This allows specifying custom conflict behavior using .on_conflict().
        If no special behavior was specified, this uses the normal Django create(..)

        Arguments:
            fields:
                The fields of the row to create.

        Returns:
            The model instance representing the row that was created.
        """

        if not self.conflict_target and not self.conflict_action:
            # no special action required, use the standard Django create(..)
            return super().create(**fields)

        compiler = self._build_insert_compiler([fields])
        rows = compiler.execute_sql(return_id=False)

        columns = rows[0]

        # get a list of columns that are officially part of the model and preserve the fact that the attribute name
        # might be different than the database column name
        model_columns = {}
        for field in self.model._meta.local_concrete_fields:
            model_columns[field.column] = field.attname

        # strip out any columns/fields returned by the db that
        # are not present in the model
        model_init_fields = {}
        for column_name, column_value in columns.items():
            try:
                model_init_fields[model_columns[column_name]] = column_value
            except KeyError:
                pass

        return self.model(**model_init_fields)
def insert_and_get(self, **fields):
        if not self.conflict_target and not self.conflict_action:
            # no special action required, use the standard Django create(..)
            return super().create(**fields)

        compiler = self._build_insert_compiler([fields])
        rows = compiler.execute_sql(return_id=False)

        columns = rows[0]

        # get a list of columns that are officially part of the model and preserve the fact that the attribute name
        # might be different than the database column name
        model_columns = {}
        for field in self.model._meta.local_concrete_fields:
            model_columns[field.column] = field.attname

        # strip out any columns/fields returned by the db that
        # are not present in the model
        model_init_fields = {}
        for column_name, column_value in columns.items():
            try:
                model_init_fields[model_columns[column_name]] = column_value
            except KeyError:
                pass

        return self.model(**model_init_fields)
def insert_and_get ( self , * * fields ) : if not self . conflict_target and not self . conflict_action : # no special action required, use the standard Django create(..) return super ( ) . create ( * * fields ) compiler = self . _build_insert_compiler ( [ fields ] ) rows = compiler . execute_sql ( return_id = False ) columns = rows [ 0 ] # get a list of columns that are officially part of the model and preserve the fact that the attribute name # might be different than the database column name model_columns = { } for field in self . model . _meta . local_concrete_fields : model_columns [ field . column ] = field . attname # strip out any columns/fields returned by the db that # are not present in the model model_init_fields = { } for column_name , column_value in columns . items ( ) : try : model_init_fields [ model_columns [ column_name ] ] = column_value except KeyError : pass return self . model ( * * model_init_fields )
Creates a new record in the database and then gets
        the entire row.

        This allows specifying custom conflict behavior using .on_conflict().
        If no special behavior was specified, this uses the normal Django create(..)

        Arguments:
            fields:
                The fields of the row to create.

        Returns:
            The model instance representing the row that was created.
Creates a new record in the database and then gets the entire row .