Skip to content

Commit 3a4e1b0

Browse files
Merge pull request DjangoGirls#1237 from brondsem/queryset
Change more output samples to current QuerySet output
2 parents 9aa5e5e + fa156f0 commit 3a4e1b0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

en/django_orm/README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Now we can finally create our post:
100100
{% filename %}command-line{% endfilename %}
101101
```python
102102
>>> Post.objects.create(author=me, title='Sample title', text='Test')
103+
<Post: Sample title>
103104
```
104105

105106
Hurray! Wanna check if it worked?
@@ -125,15 +126,15 @@ A big part of QuerySets is the ability to filter them. Let's say we want to find
125126
{% filename %}command-line{% endfilename %}
126127
```python
127128
>>> Post.objects.filter(author=me)
128-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
129+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
129130
```
130131

131132
Or maybe we want to see all the posts that contain the word 'title' in the `title` field?
132133

133134
{% filename %}command-line{% endfilename %}
134135
```python
135136
>>> Post.objects.filter(title__contains='title')
136-
[<Post: Sample title>, <Post: 4th title of post>]
137+
<QuerySet [<Post: Sample title>, <Post: 4th title of post>]>
137138
```
138139

139140
> **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
144145
```python
145146
>>> from django.utils import timezone
146147
>>> Post.objects.filter(published_date__lte=timezone.now())
147-
[]
148+
<QuerySet []>
148149
```
149150

150151
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
166167
{% filename %}command-line{% endfilename %}
167168
```python
168169
>>> Post.objects.filter(published_date__lte=timezone.now())
169-
[<Post: Sample title>]
170+
<QuerySet [<Post: Sample title>]>
170171
```
171172

172173

@@ -177,24 +178,25 @@ QuerySets also allow you to order the list of objects. Let's try to order them b
177178
{% filename %}command-line{% endfilename %}
178179
```python
179180
>>> Post.objects.order_by('created_date')
180-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
181+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
181182
```
182183

183184
We can also reverse the ordering by adding `-` at the beginning:
184185

185186
{% filename %}command-line{% endfilename %}
186187
```python
187188
>>> Post.objects.order_by('-created_date')
188-
[<Post: 4th title of post>, <Post: My 3rd post!>, <Post: Post number 2>, <Post: Sample title>]
189+
<QuerySet [<Post: 4th title of post>, <Post: My 3rd post!>, <Post: Post number 2>, <Post: Sample title>]>
189190
```
190191

191192

192193
### Chaining QuerySets
193194

194195
You can also combine QuerySets by **chaining** them together:
195196

196-
```
197+
```python
197198
>>> Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
199+
<QuerySet [<Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>, <Post: Sample title>]>
198200
```
199201

200202
This is really powerful and lets you write quite complex queries.

en/django_templates/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ It works! But we want the posts to be displayed like the static posts we created
6464

6565
![Figure 13.3](images/step3.png)
6666

67-
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.
67+
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.
6868

6969

7070
## One more thing

0 commit comments

Comments
 (0)