Django 5 Release - Highlights & Free Sample
Tags: django, webdev, django5release
Published: 2023-10-01 13:31:45

---
title: Django 5 Release - Highlights & Free Sample
published: true
description: Django 5.0 release is out - this article highlights the latest changes and also provides a free sample to play with.
tags: django, webdev, django5release
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zhdu43i6c5acdix2c3m.jpg
canonical_url: https://blog.appseed.us/django-5-release-summary-and-sample/
---

Hello Coders!

As [announced](https://www.djangoproject.com/weblog/2023/sep/18/django-50-alpha-1-released/) on the official **Django** site, the **Django 5.0** Version is out. The changes provided in this version are listed below.  

Curious minds and cutting-edge developers can test the new features by using the latest Django 5.x release:

```bash
$ pip install Django==5.0a1
```

In order to make this article more useful, here is an open-source Django Starter already updated to use `django==5.0a1` version and deployed on Render via a CI/CD flow:

- 👉 [Django v5.x Datta Able](https://github.com/app-generator/django-v5-datta-able) - `Source Code`
- 👉 [Django v5.x Datta Able](https://django-v5-datta.onrender.com/) - `LIVE Demo`

![Django v5.x Datta Able - Free Starter updated to Django 5.x Version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yd9jth7qqm753sgamw52.png)

--- 

> ✅ Python Compatibility  

**Django 5.x** supports Python 3.10, 3.11, and **3.12**. Please note the 4.2.x versions are the last to support Python 3.8 and 3.9.

---

> ✅ Facet filters in the admin
 
[Facet](https://docs.djangoproject.com/en/dev/ref/contrib/admin/filters/?ref=blog.appseed.us#facet-filters) counts are now shown for applied filters in the admin change list when toggled on via the UI. This behavior can be changed via the new [ModelAdmin.show_facets](https://docs.djangoproject.com/en/dev/ref/contrib/admin/?ref=blog.appseed.us#django.contrib.admin.ModelAdmin.show_facets) attribute.

---

> ✅ Simplified templates for form field rendering

**Django 5.x** introduces [two new concepts that simplify the rendering](https://docs.djangoproject.com/en/dev/topics/forms/?ref=blog.appseed.us#reusable-field-group-templates) of the related elements of a Django form field such as its label, widget, help text, and errors.  

- "field group"
- "field group templates"

**Here is the official coding sample**, provided by the RN:

```python
<form>
...
<div>
  {{ form.name.as_field_group }}
  <div class="row">
    <div class="col">{{ form.email.as_field_group }}</div>
    <div class="col">{{ form.password.as_field_group }}</div>
  </div>
</div>
...
</form>
```

---

> ✅ Database-computed default values

The new field added, [Field.db_default](https://docs.djangoproject.com/en/dev/ref/models/fields/?ref=blog.appseed.us#django.db.models.Field.db_default), parameter sets a database-computed default value. 

**Here is the official coding sample**:

```python
from django.db import models
from django.db.models.functions import Now, Pi


class MyModel(models.Model):
    age = models.IntegerField(db_default=18)
    created = models.DateTimeField(db_default=Now())
    circumference = models.FloatField(db_default=2 * Pi())
```

---

> ✅ Database generated model field

The new [GeneratedField](https://docs.djangoproject.com/en/dev/ref/models/fields/?ref=blog.appseed.us#django.db.models.GeneratedField) allows the creation of database-generated columns. 

**Here is the official coding sample**:

```python
from django.db import models
from django.db.models import F


class Square(models.Model):
    side = models.IntegerField()
    area = models.GeneratedField(expression=F("side") * F("side"), db_persist=True)
```

---

> ✅ Options for declaring field choices

[Field.choices](https://docs.djangoproject.com/en/dev/ref/models/fields/?ref=blog.appseed.us#django.db.models.Field.choices) (for model fields) and [ChoiceField.choices](https://docs.djangoproject.com/en/dev/ref/forms/fields/?ref=blog.appseed.us#django.forms.ChoiceField.choices) (for form fields) allow for more flexibility when declaring their values. In previous versions of Django, choices should either be a list of 2-tuples, or an Enumeration types subclass, but the latter required accessing the .choices attribute to provide the values in the expected form

Django 5.0 adds support for accepting a mapping or a callable instead of an iterable, and also no longer requires .choices to be used directly to expand [enumeration types](https://docs.djangoproject.com/en/dev/ref/models/fields/?ref=blog.appseed.us#field-choices-enum-types). 

**Here is the official coding sample**:

```python
from django.db import models

Medal = models.TextChoices("Medal", "GOLD SILVER BRONZE")

SPORT_CHOICES = {  # Using a mapping instead of a list of 2-tuples.
    "Martial Arts": {"judo": "Judo", "karate": "Karate"},
    "Racket": {"badminton": "Badminton", "tennis": "Tennis"},
    "unknown": "Unknown",
}

def get_scores():
    return [(i, str(i)) for i in range(10)]

class Winner(models.Model):
    medal = models.CharField(..., choices=Medal)  # Using `.choices` not required.
    sport = models.CharField(..., choices=SPORT_CHOICES)
    score = models.IntegerField(choices=get_scores)  # A callable is allowed.
```

---

> ✅ Other minor changes

- **django.contrib.admin** - jQuery is upgraded to 3.7.1.
- **django.contrib.auth** - The new asynchronous functions are now provided, using an a prefix: django.contrib.auth.aauthenticate(), aget_user(), alogin(), alogout(), and aupdate_session_auth_hash().
- **Asynchronous views** - Under ASGI, http.disconnect events are now handled. This allows views to perform any necessary cleanup if a client disconnects before the response is generated.

---

## ✅ In Summary

Django is a high-level Python web framework that simplifies and accelerates web development by providing a robust set of tools, libraries, and conventions. It emphasizes rapid development, clean and pragmatic design, and follows the "Don't Repeat Yourself" (DRY) principle.

**Since its first release in 2003**, Django has been continuously improved by a super-active community where all the new features are discussed, voted, implemented, and later released.

Today, Django continues to be a widely used and respected web framework, with an active community of developers and a rich ecosystem of packages and extensions.

--- 

## ✅ Resources

- 👉 Access [AppSeed](https://appseed.us/) and start your next project
- 👉 [Deploy Projects on Aws, Azure, and DO](https://www.docs.deploypro.dev/) via **DeployPRO**
- 👉 Create landing pages with [Simpllo, an open-source site builder](https://www.simpllo.com/)
- 👉 [Django App Generator](https://app-generator.dev/django/) - A 2nd generation App Builder