mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #34140 -- Reformatted code blocks in docs with blacken-docs.
This commit is contained in:
parent
6015bab80e
commit
14459f80ee
193 changed files with 5797 additions and 4481 deletions
|
@ -32,7 +32,8 @@ the ``admin.site.register(Question)`` line with:
|
|||
|
||||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
fields = ['pub_date', 'question_text']
|
||||
fields = ["pub_date", "question_text"]
|
||||
|
||||
|
||||
admin.site.register(Question, QuestionAdmin)
|
||||
|
||||
|
@ -62,10 +63,11 @@ up into fieldsets:
|
|||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {'fields': ['question_text']}),
|
||||
('Date information', {'fields': ['pub_date']}),
|
||||
(None, {"fields": ["question_text"]}),
|
||||
("Date information", {"fields": ["pub_date"]}),
|
||||
]
|
||||
|
||||
|
||||
admin.site.register(Question, QuestionAdmin)
|
||||
|
||||
The first element of each tuple in
|
||||
|
@ -92,6 +94,7 @@ with the admin just as we did with ``Question``:
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Choice, Question
|
||||
|
||||
# ...
|
||||
admin.site.register(Choice)
|
||||
|
||||
|
@ -135,11 +138,12 @@ registration code to read:
|
|||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {'fields': ['question_text']}),
|
||||
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
|
||||
(None, {"fields": ["question_text"]}),
|
||||
("Date information", {"fields": ["pub_date"], "classes": ["collapse"]}),
|
||||
]
|
||||
inlines = [ChoiceInline]
|
||||
|
||||
|
||||
admin.site.register(Question, QuestionAdmin)
|
||||
|
||||
This tells Django: "``Choice`` objects are edited on the ``Question`` admin page. By
|
||||
|
@ -204,7 +208,7 @@ object:
|
|||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
# ...
|
||||
list_display = ['question_text', 'pub_date']
|
||||
list_display = ["question_text", "pub_date"]
|
||||
|
||||
For good measure, let's also include the ``was_published_recently()`` method
|
||||
from :doc:`Tutorial 2 </intro/tutorial02>`:
|
||||
|
@ -214,7 +218,7 @@ from :doc:`Tutorial 2 </intro/tutorial02>`:
|
|||
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
# ...
|
||||
list_display = ['question_text', 'pub_date', 'was_published_recently']
|
||||
list_display = ["question_text", "pub_date", "was_published_recently"]
|
||||
|
||||
Now the question change list page looks like this:
|
||||
|
||||
|
@ -236,12 +240,13 @@ decorator on that method (in :file:`polls/models.py`), as follows:
|
|||
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
class Question(models.Model):
|
||||
# ...
|
||||
@admin.display(
|
||||
boolean=True,
|
||||
ordering='pub_date',
|
||||
description='Published recently?',
|
||||
ordering="pub_date",
|
||||
description="Published recently?",
|
||||
)
|
||||
def was_published_recently(self):
|
||||
now = timezone.now()
|
||||
|
@ -255,7 +260,7 @@ Edit your :file:`polls/admin.py` file again and add an improvement to the
|
|||
:attr:`~django.contrib.admin.ModelAdmin.list_filter`. Add the following line to
|
||||
``QuestionAdmin``::
|
||||
|
||||
list_filter = ['pub_date']
|
||||
list_filter = ["pub_date"]
|
||||
|
||||
That adds a "Filter" sidebar that lets people filter the change list by the
|
||||
``pub_date`` field:
|
||||
|
@ -270,7 +275,7 @@ knows to give appropriate filter options: "Any date", "Today", "Past 7 days",
|
|||
|
||||
This is shaping up well. Let's add some search capability::
|
||||
|
||||
search_fields = ['question_text']
|
||||
search_fields = ["question_text"]
|
||||
|
||||
That adds a search box at the top of the change list. When somebody enters
|
||||
search terms, Django will search the ``question_text`` field. You can use as many
|
||||
|
@ -314,15 +319,15 @@ Open your settings file (:file:`mysite/settings.py`, remember) and add a
|
|||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates'],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [BASE_DIR / "templates"],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue