From fa156f084d1cf418de87e25ca31c7877e9f67196 Mon Sep 17 00:00:00 2001 From: Dave Brondsema Date: Sat, 3 Mar 2018 12:26:15 -0500 Subject: [PATCH] Change more output samples to current QuerySet output (continues work of 7eb1e07) And fixes one little quoting syntax issue --- en/django_orm/README.md | 16 +++++++++------- en/django_templates/README.md | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/en/django_orm/README.md b/en/django_orm/README.md index 7dc1f20ba55..71cbfa21f89 100644 --- a/en/django_orm/README.md +++ b/en/django_orm/README.md @@ -100,6 +100,7 @@ Now we can finally create our post: {% filename %}command-line{% endfilename %} ```python >>> Post.objects.create(author=me, title='Sample title', text='Test') + ``` Hurray! Wanna check if it worked? @@ -125,7 +126,7 @@ A big part of QuerySets is the ability to filter them. Let's say we want to find {% filename %}command-line{% endfilename %} ```python >>> Post.objects.filter(author=me) -[, , , ] +, , , ]> ``` Or maybe we want to see all the posts that contain the word 'title' in the `title` field? @@ -133,7 +134,7 @@ Or maybe we want to see all the posts that contain the word 'title' in the `titl {% filename %}command-line{% endfilename %} ```python >>> Post.objects.filter(title__contains='title') -[, ] +, ]> ``` > **Note** There are two underscore characters (`_`) between `title` and `contains`. Django's ORM uses this rule to separate field names ("title") and operations or filters ("contains"). If you use only one underscore, you'll get an error like "FieldError: Cannot resolve keyword title_contains". @@ -144,7 +145,7 @@ You can also get a list of all published posts. We do this by filtering all the ```python >>> from django.utils import timezone >>> Post.objects.filter(published_date__lte=timezone.now()) -[] + ``` Unfortunately, the post we added from the Python console is not published yet. But we can change that! First get an instance of a post we want to publish: @@ -166,7 +167,7 @@ Now try to get list of published posts again (press the up arrow key three times {% filename %}command-line{% endfilename %} ```python >>> Post.objects.filter(published_date__lte=timezone.now()) -[] +]> ``` @@ -177,7 +178,7 @@ QuerySets also allow you to order the list of objects. Let's try to order them b {% filename %}command-line{% endfilename %} ```python >>> Post.objects.order_by('created_date') -[, , , ] +, , , ]> ``` We can also reverse the ordering by adding `-` at the beginning: @@ -185,7 +186,7 @@ We can also reverse the ordering by adding `-` at the beginning: {% filename %}command-line{% endfilename %} ```python >>> Post.objects.order_by('-created_date') -[, , , ] +, , , ]> ``` @@ -193,8 +194,9 @@ We can also reverse the ordering by adding `-` at the beginning: You can also combine QuerySets by **chaining** them together: -``` +```python >>> Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') +, , , ]> ``` This is really powerful and lets you write quite complex queries. diff --git a/en/django_templates/README.md b/en/django_templates/README.md index b0b1e0546aa..172e5be8d34 100644 --- a/en/django_templates/README.md +++ b/en/django_templates/README.md @@ -64,7 +64,7 @@ It works! But we want the posts to be displayed like the static posts we created ![Figure 13.3](images/step3.png) -Have you noticed that we used a slightly different notation this time (`{{ post.title }}` or `{{ post.text }})`? We are accessing data in each of the fields defined in our `Post` model. Also, the `|linebreaksbr` is piping the posts' text through a filter to convert line-breaks into paragraphs. +Have you noticed that we used a slightly different notation this time (`{{ post.title }}` or `{{ post.text }}`)? We are accessing data in each of the fields defined in our `Post` model. Also, the `|linebreaksbr` is piping the posts' text through a filter to convert line-breaks into paragraphs. ## One more thing