Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, and 1.9
Consider django-compat as an experiment based on the discussion on reddit. Let's see where it goes.
What started as an experiment based on this discussion on reddit has proven to be true in real life.
django-compat is under active development. To learn about other features, bug fixes, and changes, please refer to the changelog.
Two popular examples of open source reusable app that uses django-compat are django-hijack and django-background-tasks.
Want to have yours listed here? Send us a PR.
- Be able to use the LTS versions of Django and support newer versions in your app
- Use features from newer Django versions in an old one
- Manage and master the gap between different framework versions
Install compat from the PyPI or download and install manually. All relevant releases are listed here under releases.
Using one of the compatible objects is easy. For example
from compat import patterns, url
urlpatterns = patterns('ABC.views',
url(r'^abc/$', 'abc', name='abc-link'),
...
See a full example here.
Compatible object | Specifically tested | 1.4 | 1.7 | 1.8 | 1.9 | Notes |
---|---|---|---|---|---|---|
BytesIO |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
EmailValidator |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
GenericForeignKey |
✖️ | ✔️ | ✔️ | ✔️ | ❌ | |
models.GenericForeignKey |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
HttpResponseBase |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
JsonResponse |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
SortedDict |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
StringIO |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
URLValidator |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
VariableNode |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
View |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
add_to_builtins |
✖️ | ✔️ | ✔️ | ✔️ | ❌ | |
atomic |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
clean_manytomany_helptext |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
commit |
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | |
commit_on_success |
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | commit_on_success replaced by atomic in Django >= 1.8 |
force_text |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
format_html |
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | |
get_ident |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
get_model |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
get_model_name |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
get_user_model |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
get_username_field |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
handler404 |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
handler500 |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
import_module |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
import_string |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
include |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
parse_qs |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
patterns |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
python_2_unicode_compatible |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
resolve_url |
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | |
rollback |
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | Transaction savepoint (sid) is required for Django < 1.8 |
simplejson |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
slugify |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
smart_text |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
unquote_plus |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
url |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | Function used in urlpatterns |
templatetags.compat.url |
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | Templatetag; import with {% load url from compat %} |
urlencode |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
urlparse |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
urlunparse |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ | |
user_model_label |
✖️ | ✔️ | ✔️ | ✔️ | ✔️ |
- https://github.com/ubernostrum/django-compat-lint
- https://docs.djangoproject.com/en/dev/misc/api-stability/
- https://docs.djangoproject.com/en/dev/topics/python3/
- http://andrewsforge.com/presentation/upgrading-django-to-17/
Bits and bites of the following projects were re-used to build django-compat.
- https://github.com/lukaszb/django-guardian/blob/devel/guardian/compat.py
- https://github.com/evonove/django-oauth-toolkit/blob/master/oauth2_provider/compat.py
- https://github.com/toastdriven/django-tastypie/blob/master/tastypie/compat.py
- https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/compat.py
- TODO: MinValueValidator, MaxValueValidator et al. (other relevant bits are included) Django 1.8
- https://gist.github.com/theskumar/ff8de60ff6a33bdacaa8
- https://github.com/evonove/django-oauth-toolkit/blob/master/oauth2_provider/templatetags/compat.py
- https://github.com/kennethreitz/requests/blob/master/requests/compat.py
- https://github.com/mitsuhiko/jinja2/blob/master/jinja2/_compat.py
- https://github.com/jaraco/setuptools/blob/master/setuptools/compat.py
- https://github.com/mariocesar/sorl-thumbnail/blob/master/sorl/thumbnail/compat.py
### 2015/11/12
- Added
{% load url from compat %}
- 1.9 compatibility for existing objects with the following changes:
add_to_builtins
was removed for Django >= 1.9GenericForeignKey` was moved to
compat.models`` for Django >= 1.9
add_to_builtins
was added
get_query_set
/get_queryset
support was dropped again (see #29)