From 6335c9955617278ee10a7563f6112a6337a5f5d1 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sat, 8 Nov 2014 15:44:22 +0100 Subject: [PATCH] Fixed #166 -- Highlight the significance of the double underscore syntax. --- django_models/README.md | 2 ++ django_orm/README.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/django_models/README.md b/django_models/README.md index 110bc5c6348..798e1392e97 100644 --- a/django_models/README.md +++ b/django_models/README.md @@ -118,6 +118,8 @@ Let's open `blog/models.py`, remove everything from it and write code like this: def __str__(self): return self.title +> **Note** Double-check that you used two undescore characters (`_`) on each side of `str`. Those are used frequently in Python and sometimes we also call them "dunder" (short for "double-underscore"). + It is scary, right? But no worries, we will explain what these lines mean! All lines starting with `from` or `import` are lines that add some bits from other files. So instead of copying and pasting the same things in every file, we can include some parts with `from ... import ...`. diff --git a/django_orm/README.md b/django_orm/README.md index 1ea10a2ae9c..664a82de1b2 100644 --- a/django_orm/README.md +++ b/django_orm/README.md @@ -99,6 +99,8 @@ Or maybe we want to see all the posts that contain a word 'title' in the `title` >>> Post.objects.filter(title__contains='title') [, ] +> **Note** There are two underscore characters (`_`) between `title` and `contains`. Django's ORM uses this syntax to separate field names ("title") and operations or filters ("contains"). If you only use one underscore, you'll get an error like "FieldError: Cannot resolve keyword title_contains". + You can also get a list of all published posts. We do it by filtering all the posts that have `published_date`: >>> Post.objects.filter(published_date__isnull=False)