mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +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
|
@ -148,7 +148,7 @@ These concepts are represented by Python classes. Edit the
|
|||
|
||||
class Question(models.Model):
|
||||
question_text = models.CharField(max_length=200)
|
||||
pub_date = models.DateTimeField('date published')
|
||||
pub_date = models.DateTimeField("date published")
|
||||
|
||||
|
||||
class Choice(models.Model):
|
||||
|
@ -220,13 +220,13 @@ this:
|
|||
:caption: ``mysite/settings.py``
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'polls.apps.PollsConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
"polls.apps.PollsConfig",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
]
|
||||
|
||||
Now Django knows to include the ``polls`` app. Let's run another command:
|
||||
|
@ -430,11 +430,13 @@ representation of this object. Let's fix that by editing the ``Question`` model
|
|||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Question(models.Model):
|
||||
# ...
|
||||
def __str__(self):
|
||||
return self.question_text
|
||||
|
||||
|
||||
class Choice(models.Model):
|
||||
# ...
|
||||
def __str__(self):
|
||||
|
@ -484,7 +486,7 @@ Save these changes and start a new Python interactive shell by running
|
|||
# keyword arguments.
|
||||
>>> Question.objects.filter(id=1)
|
||||
<QuerySet [<Question: What's up?>]>
|
||||
>>> Question.objects.filter(question_text__startswith='What')
|
||||
>>> Question.objects.filter(question_text__startswith="What")
|
||||
<QuerySet [<Question: What's up?>]>
|
||||
|
||||
# Get the question that was published this year.
|
||||
|
@ -522,11 +524,11 @@ Save these changes and start a new Python interactive shell by running
|
|||
<QuerySet []>
|
||||
|
||||
# Create three choices.
|
||||
>>> q.choice_set.create(choice_text='Not much', votes=0)
|
||||
>>> q.choice_set.create(choice_text="Not much", votes=0)
|
||||
<Choice: Not much>
|
||||
>>> q.choice_set.create(choice_text='The sky', votes=0)
|
||||
>>> q.choice_set.create(choice_text="The sky", votes=0)
|
||||
<Choice: The sky>
|
||||
>>> c = q.choice_set.create(choice_text='Just hacking again', votes=0)
|
||||
>>> c = q.choice_set.create(choice_text="Just hacking again", votes=0)
|
||||
|
||||
# Choice objects have API access to their related Question objects.
|
||||
>>> c.question
|
||||
|
@ -547,7 +549,7 @@ Save these changes and start a new Python interactive shell by running
|
|||
<QuerySet [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]>
|
||||
|
||||
# Let's delete one of the choices. Use delete() for that.
|
||||
>>> c = q.choice_set.filter(choice_text__startswith='Just hacking')
|
||||
>>> c = q.choice_set.filter(choice_text__startswith="Just hacking")
|
||||
>>> c.delete()
|
||||
|
||||
For more information on model relations, see :doc:`Accessing related objects
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue