Refs #34140 -- Corrected rst code-block and various formatting issues in docs.

This commit is contained in:
Joseph Victor Zammit 2023-01-23 21:29:05 +01:00 committed by Mariusz Felisiak
parent c67ea79aa9
commit ba755ca131
57 changed files with 443 additions and 269 deletions

View file

@ -74,9 +74,9 @@ p2 doesn't have an associated restaurant:
>>> from django.core.exceptions import ObjectDoesNotExist
>>> try:
>>> p2.restaurant
>>> except ObjectDoesNotExist:
>>> print("There is no restaurant here.")
... p2.restaurant
... except ObjectDoesNotExist:
... print("There is no restaurant here.")
There is no restaurant here.
You can also use ``hasattr`` to avoid the need for exception catching:

View file

@ -675,7 +675,9 @@ Field name restrictions
Django places some restrictions on model field names:
#. A field name cannot be a Python reserved word, because that would result
in a Python syntax error. For example::
in a Python syntax error. For example:
.. code-block:: text
class Example(models.Model):
pass = models.IntegerField() # 'pass' is a reserved word!
@ -1221,7 +1223,9 @@ subclass with a :class:`~django.db.models.ManyToManyField`::
class Supplier(Place):
customers = models.ManyToManyField(Place)
This results in the error::
This results in the error:
.. code-block:: pytb
Reverse query name for 'Supplier.customers' clashes with reverse query
name for 'Supplier.place_ptr'.

View file

@ -1067,7 +1067,7 @@ query for SQL ``NULL``, use :lookup:`isnull`:
<Dog: Archie>
>>> Dog.objects.filter(data=None)
<QuerySet [<Dog: Archie>]>
>>> Dog.objects.filter(data=Value(None, JSONField())
>>> Dog.objects.filter(data=Value(None, JSONField()))
<QuerySet [<Dog: Archie>]>
>>> Dog.objects.filter(data__isnull=True)
<QuerySet [<Dog: Max>]>
@ -1356,7 +1356,9 @@ For example, this statement yields a single ``Q`` object that represents the
Q(question__startswith='Who') | Q(question__startswith='What')
This is equivalent to the following SQL ``WHERE`` clause::
This is equivalent to the following SQL ``WHERE`` clause:
.. code-block: sql
WHERE question LIKE 'Who%' OR question LIKE 'What%'

View file

@ -309,7 +309,8 @@ alias::
from django.db import connections
with connections['my_db_alias'].cursor() as cursor:
# Your code here...
# Your code here
...
By default, the Python DB API will return results without their field names,
which means you end up with a ``list`` of values, rather than a ``dict``. At a