├── .gitignore ├── README.md ├── changelog.md ├── code ├── chapter_01_example_01.py ├── chapter_01_example_02.py ├── chapter_01_example_03.py ├── chapter_01_example_04.py ├── chapter_01_example_05.py ├── chapter_01_example_06.py ├── chapter_01_example_07.py ├── chapter_01_example_08.py ├── chapter_01_example_09.py ├── chapter_02_example_01.txt ├── chapter_02_example_02.txt ├── chapter_03_example_01.txt ├── chapter_03_example_02.txt ├── chapter_03_example_03.txt ├── chapter_03_example_04.txt ├── chapter_03_example_05.txt ├── chapter_03_example_06.txt ├── chapter_03_example_07.txt ├── chapter_03_example_08.txt ├── chapter_03_example_09.txt ├── chapter_03_example_10.txt ├── chapter_04_example_01.txt ├── chapter_04_example_02.txt ├── chapter_05_example_01.txt ├── chapter_05_example_02.txt ├── chapter_05_example_03.txt ├── chapter_05_example_04.py ├── chapter_05_example_05.txt ├── chapter_05_example_06.py ├── chapter_05_example_07.txt ├── chapter_05_example_08.txt ├── chapter_05_example_09.txt ├── chapter_05_example_10.txt ├── chapter_05_example_11.txt ├── chapter_05_example_12.txt ├── chapter_05_example_13.txt ├── chapter_05_example_14.txt ├── chapter_05_example_15.py ├── chapter_05_example_16.py ├── chapter_05_example_17.py ├── chapter_05_example_18.py ├── chapter_05_example_19.py ├── chapter_05_example_20.json ├── chapter_05_example_21.py ├── chapter_05_example_22.txt ├── chapter_05_example_23.txt ├── chapter_05_example_24.txt ├── chapter_05_example_25.txt ├── chapter_05_example_26.txt ├── chapter_05_example_27.txt ├── chapter_05_example_28.txt ├── chapter_05_example_29.py ├── chapter_05_example_30.py ├── chapter_05_example_31.py ├── chapter_06_example_01.py ├── chapter_06_example_02.py ├── chapter_06_example_03.py ├── chapter_06_example_04.py ├── chapter_06_example_05.py ├── chapter_06_example_06.py ├── chapter_06_example_07.py ├── chapter_06_example_08.py ├── chapter_06_example_09.py ├── chapter_06_example_10.py ├── chapter_06_example_11.py ├── chapter_07_example_01.py ├── chapter_07_example_02.py ├── chapter_07_example_03.py ├── chapter_07_example_04.py ├── chapter_07_example_05.py ├── chapter_07_example_06.py ├── chapter_07_example_07.py ├── chapter_07_example_08.py ├── chapter_07_example_09.sql ├── chapter_07_example_10.py ├── chapter_07_example_11.py ├── chapter_08_example_01.py ├── chapter_08_example_02.py ├── chapter_08_example_03.py ├── chapter_08_example_04.py ├── chapter_08_example_05.py ├── chapter_08_example_06.html ├── chapter_08_example_07.py ├── chapter_08_example_08.html ├── chapter_08_example_09.py ├── chapter_08_example_10.py ├── chapter_08_example_11.py ├── chapter_08_example_12.py ├── chapter_08_example_13.py ├── chapter_09_example_01.py ├── chapter_09_example_02.py ├── chapter_09_example_03.py ├── chapter_09_example_04.py ├── chapter_09_example_05.py ├── chapter_09_example_06.py ├── chapter_09_example_07.py ├── chapter_10_example_01.py ├── chapter_10_example_02.py ├── chapter_10_example_03.py ├── chapter_10_example_04.py ├── chapter_10_example_05.py ├── chapter_10_example_06.html ├── chapter_10_example_07.py ├── chapter_10_example_08.py ├── chapter_10_example_09.py ├── chapter_10_example_10.html ├── chapter_10_example_11.py ├── chapter_10_example_12.html ├── chapter_10_example_13.py ├── chapter_10_example_14.py ├── chapter_11_example_01.py ├── chapter_11_example_02.py ├── chapter_11_example_03.py ├── chapter_11_example_04.py ├── chapter_11_example_05.py ├── chapter_11_example_06.py ├── chapter_11_example_07.py ├── chapter_11_example_08.py ├── chapter_11_example_09.py ├── chapter_11_example_10.py ├── chapter_11_example_11.py ├── chapter_11_example_12.py ├── chapter_11_example_13.py ├── chapter_11_example_14.py ├── chapter_11_example_15.py ├── chapter_11_example_16.py ├── chapter_11_example_17.html ├── chapter_11_example_18.html ├── chapter_12_example_01.py ├── chapter_12_example_02.py ├── chapter_12_example_03.html ├── chapter_12_example_04.py ├── chapter_12_example_05.py ├── chapter_12_example_06.py ├── chapter_12_example_07.py ├── chapter_12_example_08.py ├── chapter_12_example_09.py ├── chapter_12_example_10.py ├── chapter_13_example_01.txt ├── chapter_13_example_02.txt ├── chapter_13_example_03.txt ├── chapter_13_example_04.txt ├── chapter_13_example_05.py ├── chapter_13_example_06.html ├── chapter_13_example_07.py ├── chapter_13_example_08.html ├── chapter_13_example_09.py ├── chapter_13_example_10.html ├── chapter_13_example_11.html ├── chapter_13_example_12.html ├── chapter_13_example_13.html ├── chapter_13_example_14.html ├── chapter_13_example_15.html ├── chapter_13_example_16.html ├── chapter_13_example_17.html ├── chapter_13_example_18.html ├── chapter_13_example_19.html ├── chapter_13_example_20.html ├── chapter_13_example_21.html ├── chapter_13_example_22.html ├── chapter_13_example_23.html ├── chapter_13_example_24.py ├── chapter_14_example_01.html ├── chapter_14_example_02.py ├── chapter_15_example_01.html ├── chapter_15_example_02.py ├── chapter_15_example_03.html ├── chapter_15_example_04.py ├── chapter_15_example_05.html ├── chapter_15_example_06.py ├── chapter_16_example_01.py ├── chapter_16_example_02.py ├── chapter_16_example_03.py ├── chapter_16_example_04.py ├── chapter_16_example_05.py ├── chapter_16_example_06.txt ├── chapter_16_example_07.txt ├── chapter_16_example_08.txt ├── chapter_16_example_09.txt ├── chapter_16_example_10.py ├── chapter_16_example_11.py ├── chapter_16_example_12.txt ├── chapter_16_example_13.txt ├── chapter_16_example_14.txt ├── chapter_16_example_15.py ├── chapter_17_example_01.html ├── chapter_17_example_02.txt ├── chapter_19_example_01.py ├── chapter_19_example_02.py ├── chapter_19_example_03.py ├── chapter_19_example_04.py ├── chapter_20_example_01.py ├── chapter_20_example_02.py ├── chapter_20_example_03.py ├── chapter_20_example_04.py ├── chapter_20_example_05.py ├── chapter_20_example_06.py ├── chapter_21_example_01.txt ├── chapter_21_example_02.txt ├── chapter_21_example_03.txt ├── chapter_21_example_04.txt ├── chapter_21_example_05.txt ├── chapter_21_example_06.txt ├── chapter_21_example_07.txt ├── chapter_21_example_08.txt ├── chapter_21_example_09.txt ├── chapter_21_example_10.txt ├── chapter_22_example_01.txt ├── chapter_22_example_02.py ├── chapter_22_example_03.py ├── chapter_22_example_04.py ├── chapter_22_example_05.py ├── chapter_22_example_06.py ├── chapter_22_example_07.py ├── chapter_22_example_08.txt ├── chapter_22_example_09.txt ├── chapter_22_example_10.txt ├── chapter_22_example_11.py ├── chapter_23_example_01.txt ├── chapter_23_example_02.py ├── chapter_26_example_01.py ├── chapter_26_example_02.txt ├── chapter_26_example_03.py ├── chapter_26_example_04.py ├── chapter_26_example_05.py ├── chapter_26_example_06.py ├── chapter_26_example_07.py ├── chapter_26_example_08.py ├── chapter_26_example_09.py ├── chapter_26_example_10.py ├── chapter_27_example_01.py ├── chapter_27_example_02.py ├── chapter_27_example_03.py ├── chapter_27_example_04.py ├── chapter_27_example_05.py ├── chapter_27_example_06.py ├── chapter_28_example_01.py ├── chapter_28_example_02.py ├── chapter_28_example_03.txt ├── chapter_29_example_01.txt ├── chapter_29_example_02.py ├── chapter_29_example_03.py ├── chapter_29_example_04.py ├── chapter_29_example_05.py ├── chapter_29_example_06.py ├── chapter_29_example_07.py ├── chapter_29_example_08.py ├── chapter_29_example_09.py ├── chapter_29_example_10.py ├── chapter_29_example_11.py ├── chapter_33_example_01.txt ├── chapter_33_example_02.py ├── chapter_33_example_03.py ├── chapter_33_example_04.html ├── chapter_33_example_05.py ├── chapter_33_example_06.py ├── chapter_33_example_07.py └── chapter_33_example_08.py └── contributing.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Two Scoops of Django 2.0 Code Examples 2 | The official repo for Two Scoops of Django 1.11 code samples migrated to Django 2.0 3 | 4 | ## Why We Are Doing This: 5 | 6 | We aren't releasing a new edition of our book. Even with the 2.0 release, everything in Two Scoops of Django 1.11 will work without modification. However, for the sake of convienance, we've provided updated code examples here that work with Django 2.0 and Python 3.6. 7 | 8 | ## Buy Our books 9 | 10 | The title says "Two Scoops of Django 1.11", but it works fine with Django 2.0. We know, because we're using it in production ourselves. 11 | 12 | [![Two Scoops of Django 1.11](https://cdn.shopify.com/s/files/1/0304/6901/files/tsd-111-alpha-thumbnail.jpg?v=1493066333 "Two Scoops of Django 1.11")](https://www.twoscoopspress.com/products/two-scoops-of-django-1-11) 13 | 14 | Available in ebook and print formats at https://www.twoscoopspress.com/products/two-scoops-of-django-1-11 15 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Two Scoops of Django 2.0 Code Examples Changelog 2 | 3 | ## December 2 4 | 5 | * Repo creation 6 | * Inception 7 | 8 | -------------------------------------------------------------------------------- /code/chapter_01_example_04.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django import forms 39 | from django.db import models 40 | -------------------------------------------------------------------------------- /code/chapter_01_example_05.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # ANTI-PATTERN: Don't do this! 39 | from django.forms import * 40 | from django.db.models import * 41 | -------------------------------------------------------------------------------- /code/chapter_01_example_06.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # ANTI-PATTERN: Don't do this! 39 | from django.db.models import CharField 40 | from django.forms import CharField 41 | -------------------------------------------------------------------------------- /code/chapter_01_example_07.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django.db.models import CharField as ModelCharField 39 | from django.forms import CharField as FormCharField 40 | -------------------------------------------------------------------------------- /code/chapter_01_example_08.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | patterns = [ 39 | path(route='add/', 40 | view=views.add_topping, 41 | name='add-topping'), 42 | ] 43 | -------------------------------------------------------------------------------- /code/chapter_01_example_09.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | patterns = [ 39 | path(route='add/', 40 | view=views.add_topping, 41 | name='add_topping'), 42 | ] 43 | -------------------------------------------------------------------------------- /code/chapter_02_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ source ~/.virtualenvs/twoscoops/bin/activate 39 | -------------------------------------------------------------------------------- /code/chapter_02_example_02.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ workon twoscoops 39 | -------------------------------------------------------------------------------- /code/chapter_03_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | django-admin.py startproject mysite 39 | cd mysite 40 | django-admin.py startapp my_app 41 | -------------------------------------------------------------------------------- /code/chapter_03_example_03.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | / 39 | ├── / 40 | ├── / 41 | -------------------------------------------------------------------------------- /code/chapter_03_example_05.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | ~/projects/icecreamratings_project/ 39 | ~/.envs/icecreamratings/ 40 | -------------------------------------------------------------------------------- /code/chapter_03_example_06.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | c:\projects\icecreamratings_project\ 39 | c:\envs\icecreamratings\ 40 | -------------------------------------------------------------------------------- /code/chapter_03_example_07.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | ~/.virtualenvs/icecreamratings/ 39 | -------------------------------------------------------------------------------- /code/chapter_03_example_08.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ pip freeze 39 | -------------------------------------------------------------------------------- /code/chapter_03_example_09.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ pip freeze > requirements.txt 39 | -------------------------------------------------------------------------------- /code/chapter_04_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | # Common modules 39 | scoops/ 40 | ├── __init__.py 41 | ├── admin.py 42 | ├── forms.py 43 | ├── management/ 44 | ├── migrations/ 45 | ├── models.py 46 | ├── templatetags/ 47 | ├── tests/ 48 | ├── urls.py 49 | ├── views.py 50 | -------------------------------------------------------------------------------- /code/chapter_05_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | settings/ 39 | ├── __init__.py 40 | ├── base.py 41 | ├── local.py 42 | ├── staging.py 43 | ├── test.py 44 | ├── production.py 45 | -------------------------------------------------------------------------------- /code/chapter_05_example_02.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | python manage.py shell --settings=twoscoops.settings.local 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_03.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | python manage.py runserver --settings=twoscoops.settings.local 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_05.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | python manage.py runserver --settings=twoscoops.settings.local 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_06.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # settings/local_pydanny.py 39 | from .local import * 40 | 41 | # Set short cache timeout 42 | CACHE_TIMEOUT = 30 43 | -------------------------------------------------------------------------------- /code/chapter_05_example_07.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | settings/ 39 | __init__.py 40 | base.py 41 | local_audreyr.py 42 | local_pydanny.py 43 | local.py 44 | staging.py 45 | test.py 46 | production.py 47 | -------------------------------------------------------------------------------- /code/chapter_05_example_08.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | export SOME_SECRET_KEY=1c3-cr3am-15-yummy 39 | export AUDREY_FREEZER_KEY=y34h-r1ght-d0nt-t0uch-my-1c3-cr34m 40 | -------------------------------------------------------------------------------- /code/chapter_05_example_09.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | > setx SOME_SECRET_KEY 1c3-cr3am-15-yummy 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_10.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | [Environment]::SetEnvironmentVariable('SOME_SECRET_KEY', 39 | '1c3-cr3am-15-yummy', 'User') 40 | [Environment]::SetEnvironmentVariable('AUDREY_FREEZER_KEY', 41 | 'y34h-r1ght-d0nt-t0uch-my-1c3-cr34m', 'User') 42 | -------------------------------------------------------------------------------- /code/chapter_05_example_12.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | unset SOME_SECRET_KEY 39 | unset AUDREY_FREEZER_KEY 40 | -------------------------------------------------------------------------------- /code/chapter_05_example_13.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | [Environment]::UnsetEnvironmentVariable('SOME_SECRET_KEY', 'User') 39 | [Environment]::UnsetEnvironmentVariable('AUDREY_FREEZER_KEY', 'User') 40 | -------------------------------------------------------------------------------- /code/chapter_05_example_14.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | eb setenv SOME_SECRET_KEY=1c3-cr3am-15-yummy # Elastic Beanstalk 39 | heroku config:set SOME_SECRET_KEY=1c3-cr3am-15-yummy # Heroku 40 | -------------------------------------------------------------------------------- /code/chapter_05_example_15.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> import os 39 | >>> os.environ['SOME_SECRET_KEY'] 40 | '1c3-cr3am-15-yummy' 41 | -------------------------------------------------------------------------------- /code/chapter_05_example_16.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # Top of settings/production.py 39 | import os 40 | SOME_SECRET_KEY = os.environ['SOME_SECRET_KEY'] 41 | -------------------------------------------------------------------------------- /code/chapter_05_example_18.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | SOME_SECRET_KEY = get_env_variable('SOME_SECRET_KEY') 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_19.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | django.core.exceptions.ImproperlyConfigured: Set the SOME_SECRET_KEY 39 | environment variable. 40 | -------------------------------------------------------------------------------- /code/chapter_05_example_20.json: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | { 39 | "FILENAME": "secrets.json", 40 | "SECRET_KEY": "I've got a secret!", 41 | "DATABASES_HOST": "127.0.0.1", 42 | "PORT": "5432" 43 | } 44 | -------------------------------------------------------------------------------- /code/chapter_05_example_22.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | requirements/ 39 | ├── base.txt 40 | ├── local.txt 41 | ├── staging.txt 42 | ├── production.txt 43 | -------------------------------------------------------------------------------- /code/chapter_05_example_23.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | Django==1.11.0 39 | psycopg2==2.6.2 40 | djangorestframework==3.4.0 41 | -------------------------------------------------------------------------------- /code/chapter_05_example_24.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | -r base.txt # includes the base.txt requirements file 39 | 40 | coverage==4.2 41 | django-debug-toolbar==1.5 42 | -------------------------------------------------------------------------------- /code/chapter_05_example_25.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | -r base.txt # includes the base.txt requirements file 39 | 40 | coverage==4.2 41 | django-jenkins==0.19.0 42 | -------------------------------------------------------------------------------- /code/chapter_05_example_26.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | -r base.txt # includes the base.txt requirements file 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_27.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | pip install -r requirements/local.txt 39 | -------------------------------------------------------------------------------- /code/chapter_05_example_28.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | pip install -r requirements/production.txt 39 | -------------------------------------------------------------------------------- /code/chapter_06_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | class Meta: 39 | abstract = True 40 | -------------------------------------------------------------------------------- /code/chapter_06_example_03.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # flavors/models.py 39 | from django.db import models 40 | 41 | from core.models import TimeStampedModel 42 | 43 | class Flavor(TimeStampedModel): 44 | title = models.CharField(max_length=200) 45 | -------------------------------------------------------------------------------- /code/chapter_06_example_06.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> from orders.models import IceCreamOrder 39 | >>> IceCreamOrder.objects.filter(flavor=IceCreamOrder.FLAVOR_CHOCOLATE) 40 | [, , ] 41 | -------------------------------------------------------------------------------- /code/chapter_06_example_08.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> from orders.models import IceCreamOrder 39 | >>> chocolate = IceCreamOrder.FLAVORS.get_value('chocolate') 40 | >>> IceCreamOrder.objects.filter(flavor=chocolate) 41 | [, , ] 42 | -------------------------------------------------------------------------------- /code/chapter_06_example_10.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> from reviews.models import FlavorReview 39 | >>> FlavorReview.objects.count() 40 | 35 41 | >>> FlavorReview.objects.published().count() 42 | 31 43 | -------------------------------------------------------------------------------- /code/chapter_06_example_11.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> from reviews.models import FlavorReview 39 | >>> FlavorReview.objects.filter().count() 40 | 35 41 | >>> FlavorReview.published.filter().count() 42 | 31 43 | -------------------------------------------------------------------------------- /code/chapter_07_example_07.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # Don't do this! 39 | from models.customers import Customer 40 | 41 | customers = [] 42 | for customer in Customer.objects.iterator(): 43 | if customer.scoops_ordered > customer.store_visits: 44 | customers.append(customer) 45 | -------------------------------------------------------------------------------- /code/chapter_07_example_08.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django.db.models import F 39 | 40 | from models.customers import Customer 41 | 42 | customers = Customer.objects.filter(scoops_ordered__gt=F('store_visits')) 43 | -------------------------------------------------------------------------------- /code/chapter_07_example_09.sql: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | SELECT * from customers_customer where scoops_ordered > store_visits 39 | -------------------------------------------------------------------------------- /code/chapter_07_example_10.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # settings/base.py 39 | 40 | DATABASES = { 41 | 'default': { 42 | # ... 43 | 'ATOMIC_REQUESTS': True, 44 | }, 45 | } 46 | -------------------------------------------------------------------------------- /code/chapter_08_example_04.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | urlpatterns += [ 39 | path('tastings/', include('tastings.urls', namespace='tastings')), 40 | ] 41 | -------------------------------------------------------------------------------- /code/chapter_08_example_05.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # tastings/views.py snippet 39 | class TasteUpdateView(UpdateView): 40 | model = Tasting 41 | 42 | def get_success_url(self): 43 | return reverse('tastings:detail', 44 | kwargs={'pk': self.object.pk}) 45 | -------------------------------------------------------------------------------- /code/chapter_08_example_09.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # Django FBV as a function 39 | HttpResponse = view(HttpRequest) 40 | 41 | # Deciphered into basic math (remember functions from algebra?) 42 | y = f(x) 43 | 44 | # ... and then translated into a CBV example 45 | HttpResponse = View.as_view()(HttpRequest) 46 | 47 | -------------------------------------------------------------------------------- /code/chapter_08_example_11.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # Don't do this! 39 | def ice_cream_store_display(request, store_id): 40 | store = get_object_or_404(Store, id=store_id) 41 | date = timezone.now() 42 | return render(request, 'melted_ice_cream_report.html', locals()) 43 | -------------------------------------------------------------------------------- /code/chapter_08_example_12.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # Don't do this! 39 | def ice_cream_store_display(request, store_id): 40 | store = get_object_or_404(Store, id=store_id) 41 | now = timezone.now() 42 | return render(request, 'melted_ice_cream_report.html', locals()) 43 | -------------------------------------------------------------------------------- /code/chapter_09_example_01.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django.core.exceptions import PermissionDenied 39 | 40 | def check_sprinkle_rights(request): 41 | if request.user.can_sprinkle or request.user.is_staff: 42 | return request 43 | 44 | # Return a HTTP 403 back to the user 45 | raise PermissionDenied 46 | -------------------------------------------------------------------------------- /code/chapter_10_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # flavors/views.py 39 | from django.contrib.auth.mixins import LoginRequiredMixin 40 | from django.views.generic import DetailView 41 | 42 | from .models import Flavor 43 | 44 | class FlavorDetailView(LoginRequiredMixin, DetailView): 45 | model = Flavor 46 | -------------------------------------------------------------------------------- /code/chapter_11_example_15.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # add to flavors/views.py 39 | from django.views.generic import ListView 40 | 41 | from .models import Flavor 42 | from core.views import TitleSearchMixin 43 | 44 | class FlavorListView(TitleSearchMixin, ListView): 45 | model = Flavor 46 | -------------------------------------------------------------------------------- /code/chapter_11_example_16.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # add to stores/views.py 39 | from django.views.generic import ListView 40 | 41 | from .models import Store 42 | from core.views import TitleSearchMixin 43 | 44 | class IceCreamStoreListView(TitleSearchMixin, ListView): 45 | model = Store 46 | -------------------------------------------------------------------------------- /code/chapter_11_example_17.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | {# form to go into stores/store_list.html template #} 39 |
40 | 41 | 42 |
43 | -------------------------------------------------------------------------------- /code/chapter_11_example_18.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | {# form to go into flavors/flavor_list.html template #} 39 |
40 | 41 | 42 |
43 | -------------------------------------------------------------------------------- /code/chapter_12_example_03.html: -------------------------------------------------------------------------------- 1 | 37 | 38 |
39 | -------------------------------------------------------------------------------- /code/chapter_12_example_06.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # core/models.py 39 | from django.db import models 40 | 41 | class ModelFormFailureHistory(models.Model): 42 | form_data = models.TextField() 43 | model_data = models.TextField() 44 | -------------------------------------------------------------------------------- /code/chapter_12_example_09.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # settings.py 39 | FORM_RENDERER = 'django.forms.renderers.TemplatesSetting' 40 | 41 | INSTALLED_APPS = [ 42 | ... 43 | 'django.forms', 44 | ... 45 | ] 46 | -------------------------------------------------------------------------------- /code/chapter_13_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | templates/ 39 | ├── base.html 40 | ├── ... (other sitewide templates in here) 41 | ├── freezers/ 42 | │   ├── ("freezers" app templates in here) 43 | -------------------------------------------------------------------------------- /code/chapter_13_example_02.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | freezers/ 39 | ├── templates/ 40 | │   ├── freezers/ 41 | │   │   ├── ... ("freezers" app templates in here) 42 | templates/ 43 | ├── base.html 44 | ├── ... (other sitewide templates in here) 45 | -------------------------------------------------------------------------------- /code/chapter_13_example_03.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | templates/ 39 | ├── base.html 40 | ├── dashboard.html # extends base.html 41 | ├── profiles/ 42 | │ ├── profile_detail.html # extends base.html 43 | │ ├── profile_form.html # extends base.html 44 | -------------------------------------------------------------------------------- /code/chapter_13_example_18.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | {% extends "base.html" %} 39 | {% block stylesheets %} 40 | {{ block.super }} {# this brings in project.css #} 41 | 43 | {% endblock stylesheets %} 44 | -------------------------------------------------------------------------------- /code/chapter_13_example_20.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | {% extends "base.html" %} 39 | {% comment %} 40 | By not using {% block stylesheets %}, this template inherits the 41 | stylesheets block from the base.html parent, in this case the 42 | default project.css link. 43 | {% endcomment %} 44 | -------------------------------------------------------------------------------- /code/chapter_13_example_22.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /code/chapter_13_example_23.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /code/chapter_13_example_24.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # settings/local.py 39 | TEMPLATES = [ 40 | { 41 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 42 | 'APP_DIRS': True, 43 | 'OPTIONS': 44 | 'string_if_invalid': 'INVALID EXPRESSION: %s' 45 | }, 46 | ] 47 | -------------------------------------------------------------------------------- /code/chapter_14_example_01.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | {% extends "base.html" %} 39 | 40 | {% load flavors_tags %} 41 | -------------------------------------------------------------------------------- /code/chapter_15_example_01.html: -------------------------------------------------------------------------------- 1 | 37 | 38 |
39 | 40 |
41 | -------------------------------------------------------------------------------- /code/chapter_15_example_04.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # core/mixins.py 39 | from django.template import defaultfilters 40 | 41 | class DjFilterMixin: 42 | dj = defaultfilters 43 | -------------------------------------------------------------------------------- /code/chapter_16_example_01.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | REST_FRAMEWORK = { 39 | 'DEFAULT_PERMISSION_CLASSES': ( 40 | 'rest_framework.permissions.IsAdminUser', 41 | ), 42 | } 43 | -------------------------------------------------------------------------------- /code/chapter_16_example_06.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | flavors/api/ 39 | flavors/api/:uuid/ 40 | -------------------------------------------------------------------------------- /code/chapter_16_example_07.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | flavors/ 39 | ├── api/ 40 | │   ├── __init__.py 41 | │   ├── authentication.py 42 | │   ├── parsers.py 43 | │   ├── permissions.py 44 | │   ├── renderers.py 45 | │   ├── serializers.py 46 | │   ├── validators.py 47 | │   ├── views.py 48 | │   ├── viewsets.py 49 | -------------------------------------------------------------------------------- /code/chapter_16_example_08.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | flavors/ 39 | ├── api/ 40 | │   ├── __init__.py 41 | │   ├── ... other modules here 42 | │   ├── views 43 | │   │   ├── __init__.py 44 | │   │   ├── flavor.py 45 | │   │   ├── ingredient.py 46 | -------------------------------------------------------------------------------- /code/chapter_16_example_09.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | api/flavors/ # GET, POST 39 | api/flavors/:uuid/ # GET, PUT, DELETE 40 | api/users/ # GET, POST 41 | api/users/:uuid/ # GET, PUT, DELETE 42 | -------------------------------------------------------------------------------- /code/chapter_16_example_12.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | /sundae/ # GET, POST 39 | /sundae/:uuid/ # PUT, DELETE 40 | /sundae/:uuid/syrup/ # GET, POST 41 | /syrup/ # GET, POST 42 | /syrup/:uuid/ # PUT, DELETE 43 | -------------------------------------------------------------------------------- /code/chapter_16_example_13.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | /api/cones/ # GET, POST 39 | /api/cones/:uuid/ # PUT, DELETE 40 | /api/scoops/ # GET, POST 41 | /api/scoops/:uuid/ # PUT, DELETE 42 | -------------------------------------------------------------------------------- /code/chapter_16_example_14.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | /api/cones/ # GET, POST 39 | /api/cones/:uuid/ # PUT, DELETE 40 | /api/cones/:uuid/scoops/ # GET, POST 41 | /api/cones/:uuid/scoops/:uuid/ # PUT, DELETE 42 | /api/scoops/ # GET, POST 43 | /api/scoops/:uuid/ # PUT, DELETE 44 | -------------------------------------------------------------------------------- /code/chapter_17_example_01.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | 39 | 41 | {% csrf_token %} 42 | 43 | -------------------------------------------------------------------------------- /code/chapter_17_example_02.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | var csrfToken = $('[name=csrfmiddlewaretoken]').val(); 39 | var formData = { 40 | csrfmiddlewaretoken: csrfToken, 41 | name=name, age=age 42 | }; 43 | $.ajax({ 44 | url: '/api/do-something/'', 45 | data: formData, 46 | type: 'POST' 47 | }) 48 | -------------------------------------------------------------------------------- /code/chapter_19_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> IceCreamBar.objects.all() 39 | [, , 40 | ] 41 | -------------------------------------------------------------------------------- /code/chapter_19_example_03.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django.contrib import admin 39 | 40 | from .models import IceCreamBar 41 | 42 | @admin.register(IceCreamBar) 43 | class IceCreamBarModelAdmin(admin.ModelAdmin): 44 | list_display = ('name', 'shell', 'filling') 45 | -------------------------------------------------------------------------------- /code/chapter_20_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django.conf import settings 39 | from django.db import models 40 | 41 | class IceCreamStore(models.Model): 42 | 43 | owner = models.OneToOneField(settings.AUTH_USER_MODEL) 44 | title = models.CharField(max_length=255) 45 | -------------------------------------------------------------------------------- /code/chapter_20_example_05.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | AUTH_USER_MODEL = 'profiles.KarmaUser' 39 | -------------------------------------------------------------------------------- /code/chapter_21_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | Django==1.11 39 | coverage==4.3.4 40 | django-extensions==1.7.6 41 | django-braces==1.11 42 | -------------------------------------------------------------------------------- /code/chapter_21_example_02.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | 39 | -e git+https://github.com/erly-adptr/py-junk.git#egg=py-jnk 40 | -------------------------------------------------------------------------------- /code/chapter_21_example_03.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | # DON'T DO THIS! 39 | # requirements for django-blarg 40 | 41 | Django==1.10.2 42 | requests==1.2.3 43 | -------------------------------------------------------------------------------- /code/chapter_21_example_05.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | # requirements for django-blarg 39 | 40 | Django>=1.10,<1.12 41 | requests>=2.6.0,<=2.13.0 42 | -------------------------------------------------------------------------------- /code/chapter_21_example_07.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ pip install twine 39 | $ python setup.py sdist 40 | $ twine upload dist/* 41 | 42 | -------------------------------------------------------------------------------- /code/chapter_21_example_08.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ pip install wheel 39 | -------------------------------------------------------------------------------- /code/chapter_21_example_09.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ python setup.py bdist_wheel 39 | $ twine upload dist/* 40 | -------------------------------------------------------------------------------- /code/chapter_21_example_10.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | # setup.cfg 39 | [wheel] 40 | universal = 1 41 | -------------------------------------------------------------------------------- /code/chapter_22_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | popsicles/ 39 | __init__.py 40 | admin.py 41 | forms.py 42 | models.py 43 | tests/ 44 | __init__.py 45 | test_forms.py 46 | test_models.py 47 | test_views.py 48 | views.py 49 | -------------------------------------------------------------------------------- /code/chapter_22_example_08.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ coverage run manage.py test --settings=twoscoops.settings.test 39 | -------------------------------------------------------------------------------- /code/chapter_22_example_09.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | Creating test database for alias "default"... 39 | .. 40 | ----------------------------------------------- 41 | Ran 2 tests in 0.008s 42 | 43 | OK 44 | 45 | Destroying test database for alias "default"... 46 | -------------------------------------------------------------------------------- /code/chapter_22_example_10.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | $ coverage html --omit="admin.py" 39 | -------------------------------------------------------------------------------- /code/chapter_23_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # setup.py 39 | import subprocess 40 | import sys 41 | 42 | if sys.argv[-1] == 'md2rst': 43 | subprocess.call('pandoc README.md -o README.rst', shell=True) 44 | ... 45 | -------------------------------------------------------------------------------- /code/chapter_26_example_01.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | SESSION_COOKIE_SECURE = True 39 | CSRF_COOKIE_SECURE = True 40 | -------------------------------------------------------------------------------- /code/chapter_26_example_02.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | Strict-Transport-Security: max-age=31536000; includeSubDomains 39 | -------------------------------------------------------------------------------- /code/chapter_26_example_03.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django import forms 39 | 40 | class SpecialForm(forms.Form): 41 | my_secret = forms.CharField( 42 | widget=forms.TextInput(attrs={'autocomplete': 'off'})) 43 | -------------------------------------------------------------------------------- /code/chapter_26_example_04.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from django import forms 39 | 40 | class SecretInPublicForm(forms.Form): 41 | 42 | my_secret = forms.CharField(widget=forms.PasswordInput()) 43 | -------------------------------------------------------------------------------- /code/chapter_27_example_06.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # You can place this snippet at the top 39 | # of models.py, views.py, or any other 40 | # file where you need to log. 41 | import logging 42 | 43 | logger = logging.getLogger(__name__) 44 | -------------------------------------------------------------------------------- /code/chapter_29_example_01.txt: -------------------------------------------------------------------------------- 1 | Using This Code Example 2 | ========================= 3 | 4 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 5 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 6 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 7 | purposes of improving book formatting. Example code is provided "as is", and 8 | is not intended to be, and should not be considered or labeled as "tutorial 9 | code". 10 | 11 | Permissions 12 | ============ 13 | 14 | In general, you may use the code we've provided with this book in your 15 | programs and documentation. You do not need to contact us for permission 16 | unless you're reproducing a significant portion of the code or using it in 17 | commercial distributions. Examples: 18 | 19 | * Writing a program that uses several chunks of code from this course does 20 | not require permission. 21 | * Selling or distributing a digital package from material taken from this 22 | book does require permission. 23 | * Answering a question by citing this book and quoting example code does not 24 | require permission. 25 | * Incorporating a significant amount of example code from this book into your 26 | product's documentation does require permission. 27 | 28 | Attributions usually include the title, author, publisher and an ISBN. For 29 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 30 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 31 | (978-0-692-91572-1)." 32 | 33 | If you feel your use of code examples falls outside fair use of the permission 34 | given here, please contact us at info@twoscoopspress.org. 35 | 36 | ******************* 37 | 38 | core/ 39 | __init__.py 40 | managers.py # contains the custom model manager(s) 41 | models.py 42 | views.py # Contains the custom view mixin(s) 43 | -------------------------------------------------------------------------------- /code/chapter_29_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | from core.managers import PublishedManager 39 | from core.views import IceCreamMixin 40 | -------------------------------------------------------------------------------- /code/chapter_29_example_03.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> from django.utils.text import slugify 39 | >>> slugify('straße') # German 40 | 'strae' 41 | -------------------------------------------------------------------------------- /code/chapter_29_example_04.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | >>> slugify('straße', allow_unicode=True) # Again with German 39 | 'straße' 40 | -------------------------------------------------------------------------------- /code/chapter_29_example_08.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # urls.py 39 | 40 | # This demonstrates the use of a custom permission denied view. The default 41 | # view is django.views.defaults.permission_denied 42 | handler403 = 'core.views.permission_denied_view' 43 | -------------------------------------------------------------------------------- /code/chapter_33_example_02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # Forgetting the 'as_view()' method 39 | path(r'', HomePageView, name='home'), 40 | -------------------------------------------------------------------------------- /code/chapter_33_example_03.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | path('', HomePageView.as_view(), name='home'), 39 | -------------------------------------------------------------------------------- /code/chapter_33_example_04.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | 41 | -------------------------------------------------------------------------------- /code/chapter_33_example_08.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using This Code Example 3 | ========================= 4 | 5 | The code examples provided are provided by Daniel Greenfeld and Audrey Roy of 6 | Two Scoops Press to help you reference Two Scoops of Django: Best Practices 7 | for Django 1.11 for Django 2.0 projects. Code Samples follow PEP-0008, with exceptions made for the 8 | purposes of improving book formatting. Example code is provided "as is", and 9 | is not intended to be, and should not be considered or labeled as "tutorial 10 | code". 11 | 12 | Permissions 13 | ============ 14 | 15 | In general, you may use the code we've provided with this book in your 16 | programs and documentation. You do not need to contact us for permission 17 | unless you're reproducing a significant portion of the code or using it in 18 | commercial distributions. Examples: 19 | 20 | * Writing a program that uses several chunks of code from this course does 21 | not require permission. 22 | * Selling or distributing a digital package from material taken from this 23 | book does require permission. 24 | * Answering a question by citing this book and quoting example code does not 25 | require permission. 26 | * Incorporating a significant amount of example code from this book into your 27 | product's documentation does require permission. 28 | 29 | Attributions usually include the title, author, publisher and an ISBN. For 30 | example, "Two Scoops of Django: Best Practices for Django 1.11, by Daniel 31 | Roy Greenfeld and Audrey Roy Greenfeld. Copyright 2017 Two Scoops Press 32 | (978-0-692-91572-1)." 33 | 34 | If you feel your use of code examples falls outside fair use of the permission 35 | given here, please contact us at info@twoscoopspress.org. 36 | """ 37 | 38 | # settings.py 39 | ALLOWED_HOSTS = [ 40 | '.djangopackages.org', 41 | '.djangopackages.com', 42 | ] 43 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | Before You Submit an Issue 2 | ---------------------------- 3 | 4 | * This is only for code examples 5 | * If we do another version, it will be for 2.2 LTS, not 2.0 or 2.1 6 | * For tracking and credit purposes, **each request for correction needs to be in it's own issue. If an issue contains 2 or more issues, we'll close it with a request for breaking up into more atomic issues.** 7 | 8 | **Editorial Note:** In order to make issues more readily searchable, we will alter titles and descriptions of issues as needed. 9 | 10 | --------------------------------------------------------------------------------