2.2.28

Latest release in branch 2.2
Released 4 years ago (April 11, 2022)

Software Django
Branch 2.2
Status LTS
End of life
End of mainstream support December 02, 2019
End of extended support April 11, 2022
First official release version 2.2
First official release date 7 years ago (April 01, 2019)
Supported
Python versions
Python 3.5 - 3.9
Release notes https://docs.djangoproject.com/en/2.2/releases/
Source code https://github.com/django/django/tree/2.2.28
Documentation https://docs.djangoproject.com/en/2.2/
Django 2.2 Releases View full list

What Is New in Django 2.2

Django 2.2 is a Long Term Support (LTS) release, bringing stability and several key enhancements. This version focuses on database constraints, improved admin interfaces, and various developer experience refinements.

Category Key Changes
New Features Database-level constraints, CheckConstraint & UniqueConstraint, admin site customization classes
Improvements Faster model saving, bulk_update(), HttpResponse improvements, admin search updates
Backend Support MariaDB recognition, Oracle 12c+ identity columns, MySQL 8+ support
Deprecations django.utils.timezone.FixedOffset, django.contrib.postgres.fields.JSONField

How does Django 2.2 improve database constraints?

This release introduces a powerful new API for defining database constraints directly from your models. You can now use CheckConstraint and UniqueConstraint classes within your model's Meta.constraints option.

In practice, this means your validation logic moves closer to the database, ensuring data integrity even if other applications access the same database. You can define complex constraints that were previously difficult to enforce at the ORM level.

from django.db import models

class Customer(models.Model):
    age = models.IntegerField()
    status = models.CharField(max_length=10)

    class Meta:
        constraints = [
            models.CheckConstraint(check=models.Q(age__gte=18), name='age_gte_18'),
            models.UniqueConstraint(fields=['status', 'age'], name='unique_status_age')
        ]

What admin customization features were added?

Django 2.2 makes the admin site more customizable through class-based configuration. The new AdminSite class allows you to override default behaviors like site headers, titles, and URLs without monkey-patching.

You can now create multiple admin site instances with different configurations, which is useful for complex projects requiring separate admin interfaces. This approach is cleaner than the previous function-based customization methods.

from django.contrib.admin import AdminSite

class CustomAdminSite(AdminSite):
    site_header = 'Custom Administration'
    site_title = 'Custom Admin Portal'
    index_title = 'Welcome to the custom admin'

custom_admin_site = CustomAdminSite(name='custom_admin')

What performance improvements should I know about?

The bulk_update() method was added, allowing you to update multiple model instances with a single query. This significantly reduces database round-trips when you need to update many objects at once.

Model saving operations became faster through optimized SQL generation. The ORM now generates more efficient INSERT and UPDATE statements, particularly noticeable when working with large datasets.

# Update multiple objects efficiently
objects_to_update = [obj1, obj2, obj3]
for obj in objects_to_update:
    obj.field = new_value

Model.objects.bulk_update(objects_to_update, ['field'])

How does HTTP response handling improve?

HttpResponse now supports context manager protocol for proper resource handling. You can use HttpResponse objects in with statements, ensuring that resources are closed properly even if exceptions occur during response processing.

The new HttpResponse.headers attribute provides a case-insensitive interface for accessing response headers. This simplifies header manipulation compared to the previous dictionary-like access.

# Using HttpResponse as context manager
with HttpResponse() as response:
    response.write('Hello')
    response.headers['X-Custom-Header'] = 'Value'
    return response

FAQ

Is Django 2.2 an LTS release?
Yes, Django 2.2 is a Long Term Support release. This means it will receive security updates and data loss fixes for an extended period, typically three years, making it suitable for production environments that require stability.

What database backends are officially supported?
Django 2.2 supports PostgreSQL, MySQL, MariaDB, SQLite, and Oracle. Notably, MariaDB is now properly recognized as a distinct database backend rather than being treated as MySQL.

Should I replace my existing JSONField imports?
Yes, you should migrate from django.contrib.postgres.fields.JSONField to django.db.models.JSONField. The old import path was deprecated in 2.2 and removed in later versions.

How does bulk_update() differ from update()?
While update() performs a single query to update multiple rows with the same values, bulk_update() allows updating different instances with different values in a single query, making it more flexible for varied updates.

What Python versions are compatible?
Django 2.2 requires Python 3.5, 3.6, or 3.7. Python 3.4 support was dropped in this release, so you'll need to upgrade your Python environment if you're still using older versions.

Releases In Branch 2.2

Version Release date
2.2.28 4 years ago
(April 11, 2022)
2.2.27 4 years ago
(February 01, 2022)
2.2.26 4 years ago
(January 04, 2022)
2.2.25 4 years ago
(December 07, 2021)
2.2.24 4 years ago
(June 02, 2021)
2.2.23 4 years ago
(May 13, 2021)
2.2.22 4 years ago
(May 06, 2021)
2.2.21 4 years ago
(May 04, 2021)
2.2.20 5 years ago
(April 06, 2021)
2.2.19 5 years ago
(February 19, 2021)
2.2.18 5 years ago
(February 01, 2021)
2.2.17 5 years ago
(November 02, 2020)
2.2.16 5 years ago
(September 01, 2020)
2.2.15 5 years ago
(August 03, 2020)
2.2.14 5 years ago
(July 01, 2020)
2.2.13 5 years ago
(June 03, 2020)
2.2.12 6 years ago
(April 01, 2020)
2.2.11 6 years ago
(March 04, 2020)
2.2.10 6 years ago
(February 03, 2020)
2.2.9 6 years ago
(December 18, 2019)
2.2.8 6 years ago
(December 02, 2019)
2.2.7 6 years ago
(November 04, 2019)
2.2.6 6 years ago
(October 01, 2019)
2.2.5 6 years ago
(September 02, 2019)
2.2.4 6 years ago
(August 01, 2019)
2.2.3 6 years ago
(July 01, 2019)
2.2.2 6 years ago
(June 03, 2019)
2.2.1 6 years ago
(May 01, 2019)
2.2 7 years ago
(April 01, 2019)
2.2rc1 7 years ago
(March 18, 2019)
2.2b1 7 years ago
(February 11, 2019)
2.2a1 7 years ago
(January 17, 2019)