diff options
| author | django-bot <ops@djangoproject.com> | 2023-02-28 20:53:28 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-01 13:03:56 +0100 |
| commit | 14459f80ee3a9e005989db37c26fd13bb6d2fab2 (patch) | |
| tree | eb62429ed696ed3a5389f3a676aecfc6d15a99cc /docs/intro/tutorial07.txt | |
| parent | 6015bab80e28aef2669f6fac53423aa65f70cb08 (diff) | |
Fixed #34140 -- Reformatted code blocks in docs with blacken-docs.
Diffstat (limited to 'docs/intro/tutorial07.txt')
| -rw-r--r-- | docs/intro/tutorial07.txt | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/docs/intro/tutorial07.txt b/docs/intro/tutorial07.txt index 14548590b3..71c13180fe 100644 --- a/docs/intro/tutorial07.txt +++ b/docs/intro/tutorial07.txt @@ -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", ], }, }, |
