What Is New in Django 1.11
Django 1.11 is a Long Term Support (LTS) release, bringing a solid set of new features, improvements, and the usual round of bug fixes. This version sets the foundation for the next few years of stable development.
| Category | Key Highlights |
|---|---|
| New Features | Class-based model indexes, Subquery expressions, Template-based widget rendering |
| Improvements | Customizable admin pagination, New database operations, django.contrib.postgres enhancements |
| Backwards Incompatibility | Context of Widget.render() changed, Removal of deprecated features |
| Deprecations | Several features deprecated for future removal |
How does Django 1.11 improve database querying?
The ORM gets significantly more powerful with the introduction of Subquery expressions. This allows you to use the output of one query directly within the WHERE clause of another, a common SQL pattern that was previously awkward to achieve.
You can now define database indexes directly on your models using a class-based approach. This is much cleaner than the old functional style and allows for more complex index types, like BrinIndex, to be declared intuitively.
Example: Subquery Expression
from django.db.models import OuterRef, Subquery
newest = Comment.objects.filter(post=OuterRef('pk')).order_by('-created_at')
Post.objects.annotate(newest_commenter_email=Subquery(newest.values('email')[:1]))
What changes were made to the admin and forms?
Widget rendering has been overhauled to use the Django template system. This makes it far easier to customize the HTML of form widgets without having to override Python methods. You can now create a templates/ directory and drop in your own widget templates.
The admin interface's pagination is now customizable. You can control the number of items shown per page by adding a new list_per_page attribute to your ModelAdmin class, giving you more flexibility for different models.
What should I know about backwards compatibility?
The context passed to the Widget.render() method has changed. If you have custom widgets that override this method, you'll need to update them to accept the new context parameter. This was done to support the new template-based widget rendering.
This release also continues the project's deprecation cycle. Features that were marked for deprecation in older versions, like the django.contrib.webdesign package and the extra_context parameter on SimpleTestCase.assertContains(), have now been removed entirely.
FAQ
Is Django 1.11 an LTS release?
Yes, Django 1.11 is a Long Term Support (LTS) release. This means it will receive security updates and data loss fixes for a longer period, typically three years, making it a preferred choice for production environments that value stability.
What is the main benefit of the new Subquery expression?
It lets you write more efficient and complex database queries directly in the ORM that previously required raw SQL or less performant workarounds. You can now annotate a queryset with data from a related model's subquery in a single operation.
Instead of overriding the
render() method, you now create a template. For a widget named MyTextInput, you would create templates/my_text_input.html and the widget will automatically use it, making HTML customization much simpler.
What was removed in this version that might break my project?
Several previously deprecated features were removed. The most common breakage could come from custom widgets that override Widget.render() without accounting for the new context parameter, or if you were still using the removed django.contrib.webdesign package.
Are there any new indexes besides the class-based syntax?
Yes, the new BrinIndex was introduced for PostgreSQL. This index type is highly space-efficient and can be very effective for large tables with naturally sorted data, like timestamped logs.