Overview
Django 5.2 LTS, released on April 2, 2025, is a long-term support release. It introduces composite primary keys, automatic model imports in the shell, and ORM improvements.
Main Features
Composite primary keys
Django finally supports composite primary keys via CompositePrimaryKey. This simplifies modeling join tables and existing schemas.
python
from django.db import models
class Enrollment(models.Model):
student = models.ForeignKey('Student', on_delete=models.CASCADE)
course = models.ForeignKey('Course', on_delete=models.CASCADE)
date = models.DateField(auto_now_add=True)
class Meta:
pk = models.CompositePrimaryKey('student_id', 'course_id')
Automatic model imports in shell
The python manage.py shell command automatically imports all project models, avoiding repetitive manual imports.
python
# python manage.py shell
# All models are automatically available:
# >>> User.objects.count()
# 42
# >>> Article.objects.filter(published=True).count()
# 15
# No more: from myapp.models import User, Article
ORM improvements
The ORM benefits from new query expressions and performance optimizations for complex joins.
python
from django.db.models import Q, F
# More expressive queries
articles = Article.objects.filter(
Q(published=True) & Q(views__gte=F('min_views'))
).select_related('author').only('title', 'author__name')
