Support all known versions of Django (backports from upstream).