def patch(self):
        """
        monkey patches django.db.models.sql.compiler.SQL*Compiler series
        """
        from django.db.models.sql import compiler

        self._read_compilers = (
            compiler.SQLCompiler,
            compiler.SQLAggregateCompiler,
            compiler.SQLDateCompiler,
        )
        self._write_compilers = (
            compiler.SQLInsertCompiler,
            compiler.SQLDeleteCompiler,
            compiler.SQLUpdateCompiler,
        )
        if not self._patched:
            self._original = {}
            for reader in self._read_compilers:
                self._original[reader] = reader.execute_sql
                reader.execute_sql = self._monkey_select(reader.execute_sql)
            for updater in self._write_compilers:
                self._original[updater] = updater.execute_sql
                updater.execute_sql = self._monkey_write(updater.execute_sql)
            self._patched = True
            self.cache_backend.patch()
            self._handle_signals()
def patch ( self ) : from django . db . models . sql import compiler self . _read_compilers = ( compiler . SQLCompiler , compiler . SQLAggregateCompiler , compiler . SQLDateCompiler , ) self . _write_compilers = ( compiler . SQLInsertCompiler , compiler . SQLDeleteCompiler , compiler . SQLUpdateCompiler , ) if not self . _patched : self . _original = { } for reader in self . _read_compilers : self . _original [ reader ] = reader . execute_sql reader . execute_sql = self . _monkey_select ( reader . execute_sql ) for updater in self . _write_compilers : self . _original [ updater ] = updater . execute_sql updater . execute_sql = self . _monkey_write ( updater . execute_sql ) self . _patched = True self . cache_backend . patch ( ) self . _handle_signals ( )
monkey patches django.db.models.sql.compiler.SQL*Compiler series