Skip to content

Pinax 18.01 Upgrading app for Django v2.0

KatherineMichel edited this page Jan 12, 2020 · 3 revisions

Bring a Pinax app into compliance with Django v2.0 by following these general steps:

  1. Use an updated tox.ini file, as seen in Converting to CircleCi. This update updates the test matrix, removing deprecated versions of Django.
  2. Run detox locally to see which test configurations fail and why.

Common Issues

  • Add on_delete=models.CASCADE (or some other value) to all ForeignKey and OneToOne model fields.
  • Use (or create) compat.py for import compatibility. Currently the only import issue we know is mock which did not exist in unittest until Python 3.3. See pinax-announcements compat.py for example imports, then use from .compat import mock for example.
  • Add URL namespacing. Add app_name = "pinax_announcements" or similar to urls.py.
  • Import from django.urls instead of django.core.urlresolvers.
  • Change MIDDLEWARE_CLASSES to MIDDLEWARE as per https://docs.djangoproject.com/en/1.11/topics/http/middleware/.
  • Use django.shortcuts.render() in place of deprecated django.shortcuts.render_to_response().
  • Use User.is_authenticated and User.is_anonymous properties in place of deprecated User.is_authenticated() and User.is_anonymous() functions.
  • Remove references to removed SessionAuthenticationMiddleware class. It provided no functionality since session authentication is unconditionally enabled in Django 1.10.
  • Change @register.assignment_tag to @register.simple_tag. See Simple Tag guidance.
  • Update documentation for INSTALLED_APPS value as a list instead of a tuple, i.e. INSTALLED_APPS = [ "app", ]. Check for other settings with the same issue.
  • Search for uses of django.contrib.auth User model. Consider using from django.contrib.auth import get_user_model instead.
  • If your application URLs includes url(r"^admin/", include(admin.site.urls)), change that to url(r"^admin/", admin.site.urls).
  • Replace context_instance=RequestContext(self.request) kwarg to render_*() functions with request=self.request.

As usual before a new release, update the version number. Recently the Pinax team decided this update, with corresponding drop of older Django version support, warrants a major version upgrade, i.e. from v2.0.4 to v3.0.0.

See pinax-announcements files for an example of these guidelines implemented in the real world.