As suggested by @xordoquy I import in the compat module OrderedDict from collections if django >= 1.7 else from django (SortedDict as OrderedDict). Not matter the version of the Python interpreter.