diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2023-02-09 16:48:46 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-02-10 21:12:06 +0100 |
| commit | b784768eef75afb32f6d2ce7166551a528bce0ec (patch) | |
| tree | a375a57a50f1766538ea8a62ec49bda352d7f2b9 /docs/ref/models/fields.txt | |
| parent | 4a89aa25c91e520c247aee428782274dcf10ffd0 (diff) | |
[4.2.x] Refs #34140 -- Applied rst code-block to non-Python examples.
Thanks to J.V. Zammit, Paolo Melchiorre, and Mariusz Felisiak for
reviews.
Backport of 534ac4829764f317cf2fbc4a18354fcc998c1425 from main.
Diffstat (limited to 'docs/ref/models/fields.txt')
| -rw-r--r-- | docs/ref/models/fields.txt | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index 8d75280a54..81f3013892 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -249,7 +249,9 @@ the ``.name`` and ``.value`` properties on the members. If you don't need to have the human-readable names translated, you can have them inferred from the member name (replacing underscores with spaces and using -title-case):: +title-case): + +.. code-block:: pycon >>> class Vehicle(models.TextChoices): ... CAR = 'C' @@ -274,7 +276,9 @@ Django provides an ``IntegerChoices`` class. For example:: It is also possible to make use of the `Enum Functional API <https://docs.python.org/3/library/enum.html#functional-api>`_ with the caveat -that labels are automatically generated as highlighted above:: +that labels are automatically generated as highlighted above: + +.. code-block:: pycon >>> MedalType = models.TextChoices('MedalType', 'GOLD SILVER BRONZE') >>> MedalType.choices @@ -1597,7 +1601,9 @@ The possible values for :attr:`~ForeignKey.on_delete` are found in ``Artist`` can be deleted even if that implies deleting an ``Album`` which is referenced by a ``Song``, because ``Song`` also references - ``Artist`` itself through a cascading relationship. For example:: + ``Artist`` itself through a cascading relationship. For example: + + .. code-block:: pycon >>> artist_one = Artist.objects.create(name='artist one') >>> artist_two = Artist.objects.create(name='artist two') @@ -2025,7 +2031,9 @@ With the following example:: related_name='supervisor_of', ) -your resulting ``User`` model will have the following attributes:: +your resulting ``User`` model will have the following attributes: + +.. code-block:: pycon >>> user = User.objects.get(pk=1) >>> hasattr(user, 'myspecialuser') |
