1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Improved readability of string interpolation in frequently used examples in docs.

This commit is contained in:
Trey Hunner 2022-11-10 04:18:38 -08:00 committed by GitHub
parent d6cbf39a1b
commit fad070b07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 10 deletions

View File

@ -558,7 +558,7 @@ subclass::
@admin.display(description='Name')
def upper_case_name(obj):
return ("%s %s" % (obj.first_name, obj.last_name)).upper()
return f"{obj.first_name} {obj.last_name}".upper()
class PersonAdmin(admin.ModelAdmin):
list_display = [upper_case_name]
@ -571,7 +571,7 @@ subclass::
@admin.display(description='Name')
def upper_case_name(self, obj):
return ("%s %s" % (obj.first_name, obj.last_name)).upper()
return f"{obj.first_name} {obj.last_name}".upper()
* A string representing a model attribute or method (without any required
arguments). For example::
@ -585,7 +585,8 @@ subclass::
@admin.display(description='Birth decade')
def decade_born_in(self):
return '%ds' % (self.birthday.year // 10 * 10)
decade = self.birthday.year // 10 * 10
return f'{decade}s'
class PersonAdmin(admin.ModelAdmin):
list_display = ['name', 'decade_born_in']

View File

@ -728,7 +728,7 @@ For example::
last_name = models.CharField(max_length=50)
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
return f'{self.first_name} {self.last_name}'
``__eq__()``
------------

View File

@ -473,7 +473,7 @@ login page::
def my_view(request):
if not request.user.is_authenticated:
return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
return redirect(f'{settings.LOGIN_URL}?next={request.path}')
# ...
...or display an error message::

View File

@ -15,7 +15,7 @@ objects, but an ``Article`` can only have one ``Reporter`` object::
email = models.EmailField()
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
return f"{self.first_name} {self.last_name}"
class Article(models.Model):
headline = models.CharField(max_length=100)

View File

@ -14,7 +14,7 @@ In this example, a ``Place`` optionally can be a ``Restaurant``::
address = models.CharField(max_length=80)
def __str__(self):
return "%s the place" % self.name
return f"{self.name} the place"
class Restaurant(models.Model):
place = models.OneToOneField(

View File

@ -762,7 +762,7 @@ For example, this model has a few custom methods::
@property
def full_name(self):
"Returns the person's full name."
return '%s %s' % (self.first_name, self.last_name)
return f'{self.first_name} {self.last_name}'
The last method in this example is a :term:`property`.

View File

@ -561,7 +561,7 @@ the historical model and iterate over the rows::
# version than this migration expects. We use the historical version.
Person = apps.get_model('yourappname', 'Person')
for person in Person.objects.all():
person.name = '%s %s' % (person.first_name, person.last_name)
person.name = f'{person.first_name} {person.last_name}'
person.save()
class Migration(migrations.Migration):

View File

@ -969,7 +969,7 @@ The code for this test may look as follows::
super().tearDownClass()
def test_login(self):
self.selenium.get('%s%s' % (self.live_server_url, '/login/'))
self.selenium.get(f'{self.live_server_url}/login/')
username_input = self.selenium.find_element(By.NAME, "username")
username_input.send_keys('myuser')
password_input = self.selenium.find_element(By.NAME, "password")