diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 938ff87cab..7a67438b38 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -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 diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index eadd036cb6..f95ff1017f 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -317,7 +317,7 @@ Sample usage:: >>> feed.add_item( ... title="Hello", ... link="http://www.holovaty.com/test/", - ... description="Testing." + ... description="Testing.", ... ) >>> with open('test.rss', 'w') as fp: ... feed.write(fp, 'utf-8') @@ -629,15 +629,19 @@ escaping HTML. So, instead of writing:: - mark_safe("%s %s %s" % (some_html, - escape(some_text), - escape(some_other_text), - )) + mark_safe("%s %s %s" % ( + some_html, + escape(some_text), + escape(some_other_text), + )) You should instead use:: format_html("{} {} {}", - mark_safe(some_html), some_text, some_other_text) + mark_safe(some_html), + some_text, + some_other_text, + ) This has the advantage that you don't need to apply :func:`escape` to each argument and risk a bug and an XSS vulnerability if you forget one. @@ -658,8 +662,10 @@ escaping HTML. ``args_generator`` should be an iterator that returns the sequence of ``args`` that will be passed to :func:`format_html`. For example:: - format_html_join('\n', "