Refs #26021 -- Used hanging indentation in some doc examples.

This commit is contained in:
Tim Graham 2016-05-14 19:06:31 -04:00
parent 5238af3257
commit e475e84970
4 changed files with 30 additions and 20 deletions

View file

@ -921,8 +921,10 @@ For example, suppose you have these models::
toppings = models.ManyToManyField(Topping)
def __str__(self): # __unicode__ on Python 2
return "%s (%s)" % (self.name, ", ".join(topping.name
for topping in self.toppings.all()))
return "%s (%s)" % (
self.name,
", ".join(topping.name or topping in self.toppings.all()),
)
and run::
@ -1669,8 +1671,11 @@ This is meant as a shortcut to boilerplatish code. For example::
This pattern gets quite unwieldy as the number of fields in a model goes up.
The above example can be rewritten using ``get_or_create()`` like so::
obj, created = Person.objects.get_or_create(first_name='John', last_name='Lennon',
defaults={'birthday': date(1940, 10, 9)})
obj, created = Person.objects.get_or_create(
first_name='John',
last_name='Lennon',
defaults={'birthday': date(1940, 10, 9)},
)
Any keyword arguments passed to ``get_or_create()`` — *except* an optional one
called ``defaults`` — will be used in a :meth:`get()` call. If an object is