From 5ac563c1ebb0c453a3ba34bfa86d12d4e22215e6 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 110bc5c6348d..89b907bf26a5 100644 --- a/django_models/README.md +++ b/django_models/README.md @@ -141,6 +141,8 @@ What about `def publish(self):`? It is exactly our `publish` method we were talk Methods very often `return` something. There is an example of that in the `__str__` method. In this scenario, when we call `__str__()` we will get a text (**string**) with a Post title. +> **Note** Yes, there are two undescore characters (`_`) on each side. Those are used frequently in Python and sometimes we also call them "dunder" (short for "double-underscore"). + If something is still not clear about models, feel free to ask your coach! We know it is very complicated, especially when you learn what objects and functions are at the same time. But hopefully it looks slightly less magic for you now! ### Create tables for models in your database diff --git a/django_orm/README.md b/django_orm/README.md index 1ea10a2ae9c5..bc900c825d56 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"). + 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)