mirror of
https://github.com/django/django.git
synced 2025-08-23 18:29:12 +00:00
[5.0.x] Refs #31300 -- Added example to GeneratedField release notes.
Backport of 0b506bfe1ab9f1c38e439c77b3c3f81c8ac663ea from main
This commit is contained in:
parent
ab5124c227
commit
7e4c1e8b3d
@ -134,7 +134,15 @@ Database generated model field
|
|||||||
|
|
||||||
The new :class:`~django.db.models.GeneratedField` allows creation of database
|
The new :class:`~django.db.models.GeneratedField` allows creation of database
|
||||||
generated columns. This field can be used on all supported database backends
|
generated columns. This field can be used on all supported database backends
|
||||||
to create a field that is always computed from other fields.
|
to create a field that is always computed from other fields. For example::
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
More options for declaring field choices
|
More options for declaring field choices
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user