Skip to content

Instantly share code, notes, and snippets.

@manfre
Created September 19, 2013 16:03

Revisions

  1. manfre created this gist Sep 19, 2013.
    17 changes: 17 additions & 0 deletions compiler.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    class SQLCompiler(compiler.SQLCompiler):
    def resolve_columns(self, row, fields=()):
    # If the results are sliced, the resultset will have an initial
    # "row number" column. Remove this column before the ORM sees it.
    if getattr(self, '_using_row_number', False):
    row = row[1:]

    values = []
    index_extra_select = len(self.query.extra_select.keys())
    for value, field in map(None, row[index_extra_select:], fields):
    if field:
    try:
    val = self.connection.ops.convert_values(value, field)
    except ValueError:
    val = value
    values.append(val)
    return row[:index_extra_select] + tuple(values)