Quoi de neuf dans
Django 5.0?
| Mainstream support | Extended support | |
|---|---|---|
| 3.2 LTS | Avr. 2024 | |
| 4.1 | Déc. 2023 | |
| 4.2 LTS | Déc. 2023 | Avr. 2026 |
| 5.0 | Aoû. 2024 | Avr. 2025 |
✨ Fin du support ✨ de Python 3.8 et 3.9
🪩 Facettes dans l’admin 💃🕺
ModelAdmin.show_facets
Simplification du rendu des formulaires
Avant
<form>
...
<div>
{{ form.name.label_tag }}
{% if form.name.help_text %}
<div class="helptext" id="{{ form.name.auto_id }}_helptext">
{{ form.name.help_text|safe }}
</div>
{% endif %}
{{ form.name.errors }}
{{ form.name }}
<div class="row">
<div class="col">
{{ form.email.label_tag }}
{% if form.email.help_text %}
<div class="helptext" id="{{ form.email.auto_id }}_helptext">
{{ form.email.help_text|safe }}
</div>
{% endif %}
{{ form.email.errors }}
{{ form.email }}
</div>
<div class="col">
{{ form.password.label_tag }}
{% if form.password.help_text %}
<div class="helptext" id="{{ form.password.auto_id }}_helptext">
{{ form.password.help_text|safe }}
</div>
{% endif %}
{{ form.password.errors }}
{{ form.password }}
</div>
</div>
</div>
...
</form>Après
<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>Ça se configure…
from django.forms.renderers import TemplatesSetting
class CustomFormRenderer(TemplatesSetting):
field_template_name = "field_snippet.html"Au niveau global
class MyForm(forms.Form):
subject = forms.CharField(template_name="my_custom_template.html")Au niveau du champ
def index(request):
form = ContactForm()
subject = form["subject"]
context = {"subject": subject.render("my_custom_template.html")}
return render(request, "index.html", context)Au niveau de la requête
Valeurs par défaut au niveau de la base de données
class MyModel(models.Model):
created = models.DateTimeField(db_default=Now())Champs de modèles avec valeurs générées
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"),
output_field=models.BigIntegerField(),
db_persist=True,
)⚠️ Uniquement des valeurs déterministes
⚠️ Pas de valeurs d’autres modèles
⚠️ Pas de référence à d’autres champs calculés
Plus d’options pour les "choices"
class Tag(models.Model):
VISIBILITY_INTERNAL = "internal"
VISIBILITY_PUBLIC = "public"
VISIBILITY_CHOICES = [
(VISIBILITY_INTERNAL, _("Internal")),
(VISIBILITY_PUBLIC, _("Public")),
]
visibility = models.Charfield(max_length=20, choices=VISIBILITY_CHOICES)class VisibilityChoices(models.TextChoices):
internal = "internal", _("Internal")
public = "public", _("Public")
class Tag(models.Model):
visibility = models.Charfield(max_length=20, choices=Visibility.choices)VISIBLITY_CHOICES = {
"internal": _("Internal"),
"public": _("Public"),
}
class Tag(models.Model):
visibility = models.Charfield(max_length=20, choices=VISIBILITY_CHOICES)Django 5
def get_order_choices():
return [(value, str(value)) for value in range(10)]
class Tag(models.Model):
order = models.IntegerField(choices=get_order_choices)Django 5
✨ C’est tout pour aujourd’hui! ✨
Quoi de neuf dansDjango 5.0?
By Sylvain Roflmao
Quoi de neuf dansDjango 5.0?
- 170