[
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: [pydanny]\npatreon: feldroy\nopen_collective: # Replace with a single Open Collective username\nko_fi: # Replace with a single Ko-fi username\ntidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel\ncommunity_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry\nliberapay: # Replace with a single Liberapay username\nissuehunt: # Replace with a single IssueHunt username\notechie: # Replace with a single Otechie username\ncustom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']\n"
  },
  {
    "path": "ISSUE_TEMPLATE",
    "content": "## Greetings! \n\nHello! As a reader, you're encouraged to submit bug reports to us for errors that you find. In turn we will give you credit for your contributions in not just the e-book but also in the print paperback. This is your opportunity to have your name in one of our books as a contributor, which you are then welcome to add to your resume and LinkedIn profile.\n\nNotes:\n\n- TODOs are markers to let you know we are going to expand an area, so reporting them during the ALPHA and BETA period **doesn't** qualify as an attributable item.\n- `??:??` are references for areas written but still being examined by our reviewers and not yet in the published version of the book. Reporting them **doesn't** qualify as an attributable item.\n\n## Location within the Book\n\n* Chapter or Appendix:\n* Section:\n* Subsection:\n\nHint: Page numbers change all the time. The best way to report an issue is by chapter, section, and subsection numbers.\n\n## Description \n\n> If grammar, enter problematic text here, otherwise delete this line.\n\n```\nIf code-related, enter it within these backticks. Otherwise, delete this segment.\n```\n\n## Possible Solutions\n\n## Your full name so we can provide accurate credit within the book\n"
  },
  {
    "path": "README.md",
    "content": "# Two Scoops of Django 3.x\nThe issue tracker, changelog, and code repository for Two Scoops of Django 3.x\n\nTracking thoughts and feature requests for Two Scoops of Django 3.x in the issue tracker.\n\nAvailable currently in PDF formats at https://www.feldroy.com/products/two-scoops-of-django-3-x. \n\n## Before You Submit an Issue\n\n* Be nice. :-)\n* Be honest.\n* Check the issues from the previous version (1.11) [open](https://github.com/twoscoops/two-scoops-of-django-1.11/issues?state=open) and [closed](https://github.com/twoscoops/two-scoops-of-django-1.11/issues?state=closed) to see if your issue already exists.\n* Check the [changelog](https://github.com/feldroy/two-scoops-of-django-3.x/blob/master/changelog.md) to see if your issue has already been resolved.\n* Please, please, please identify each issue by chapter, section, and subsection numbers. Since the content shifts around using page numbers to identify problems is innaccurate.\n* 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 may close it with a request for breaking up into more atomic issues.**\n\n**Editorial Note:** In order to make issues more readily searchable, we may alter titles and descriptions of issues as needed.\n\n## When will this be published?\n\nIt's published and you can get it at https://www.feldroy.com/products/two-scoops-of-django-3-x\n"
  },
  {
    "path": "changelog.md",
    "content": "# Two Scoops of Django Changelog\n\nThis lists many, but not all the changes between TSD 1.11 and TSD 3.x.\n\n# Updates 2023-08-16\n\n## General\n\n- Grammar corrections\n- Cleanup frontmatter\n- Zappa now pointing at github.com/zappa/zappa\n\n## Asynchronous Views\n\n- Finally admit that the Django 3 story for Asynchronous views was still in its infancy.\n\n## GraphQL\n\n- Recommend Strawberry as best-of-breed Python GraphQL libraries\n- Mention https://github.com/mirumee/ariadne-codegen for client generation\n\n## Acknowledgements\n\n- Give special thanks to Fábio C. Barrionuevo \n- Add link to Laura Gelsomino's LinkedIn profile\n\n# Updates until 2021-07-08\n\n## General\n\n- Grammar corrections\n- All form classes have `fields` defined\n\n## Javascript\n\n- Added Next and Nuxt\n- Linked to Django support for HTMX and Hotwire\n- General cleanup\n\n## GraphQL\n\n- Make Graphene a first class citizen\n- Discuss Ariadne's shortcomings\n\n## Signals\n\n- Updated signals to Django 3.2\n\n## PAAS\n\n- Added render.com and divio cloud\n- Remove mention of Heroku\n\n## Deployment\n\n- Added ASGI\n- Modernized WSGI section\n\n## Queues\n\n- Removed django-background-tasks as it is now unmaintained\n- Edit, cleanup, and unleash remaining content after subsection 1.3.5\n\n## Continuous Integration\n\n- Updated CI to Django 3.2\n\n# Updates until 2021-06-14\n\n## General\n\n- Changed our names to Daniel and Audrey Roy Greenfeld\n- Grammar and spelling corrections\n- Corrected broken links across the book\n\n## PAAS\n\n- Add Digital Ocean App Platform\n- Be honest about Heroku so users see it with open eyes\n\n## Debugging\n\n- Brought chapter in\n- Removed link to ancient blog post\n- Added mention of `breakpoint()`\n\n## Where and how to ask for help\n\n- Added section on the official forums\n- Added Libera Chat IRC\n- Linkified a few items to make things easier on readers\n\n---\n\n# Updates until 2021-01-27\n\n## General\n\n- Converted all docs links to point to Django 3.2\n\n## Coding Style\n\n- Changed `isort` tip box to a package tip\n\n## Graphql\n\n- Removed trygql.com\n\n## Security\n\n- Mention OTPs in 2FA\n\n## Logging\n\n- Chapter has been revised and is available for readers!\n- Added warning box about using f-strings with loggers\n- Removed Python 2 mention\n\n## Packages\n\n- Added aldjemy\n- Added django-stronghold\n- Added environment variable section with multiple packages\n\n---\n\n# Updates until 2020-12-02\n\n## General Changes\n\n- Added Authorized Vendors and Distributors informations\n- Various spelling and grammar corrections\n- Removed last python 2.7-style usages of `super()`\n\n## Database Queries\n\n- Use `breakpoint()` instead of importing pdb\n\n## FBVs\n\n- Added Luke Plant's \"Django Views the Right Way\"\n\n## User models\n\n- Corrected wrong parent class\n\n---\n\n# Updates until 2020-07-27\n\n## General Changes\n\n- Grammar fixes\n\n## Settings and Requirements\n\n- Add missing `ql` to ORM engine\n\n## Models and Queries\n\n- JSONField is now for all database types\n\n## Templates\n\n- Removed GitHub's 404 page from the list of being self-contained HTML, CSS, and JS\n\n## Third-party packages\n\n- Fix code highlighting\n\n## Security\n\n- Fix borked link\n\n## Appendix: Resources\n\n- Added testdriven.io\n\n---\n\n# Updates until 2020-07-09\n\n## General Changes\n\n- Moved first reference to indexes from chapter 6 to chapter 7\n- The inevitable grammar corrections\n\n## Settings and Requirements\n\n- Added `.zshrc` for configuring environment variables\n\n## Best Practices for FBVs\n\n- Made use of `functools.wraps` consistent\n\n## Best Practices for CBVs\n\n- Mixins should not inherit from `object`, that is a holdover from Python 2.7\n\n## Finding and Reducing bottlenecks\n\n- Reviewed content in full and added to the book\n\n## Third-Party Packages\n\n- Add instruction for git tagging project releases\n\n## Async Task Queues\n\n- Started on reviewing content\n\n## Internationalization\n\n- All pages updated for Django 3.x and Python 3.8\n\n---\n\n# Updates until 2020-07-07\n\nThis update adds 15 new pages to Two Scoops of Django, bringing us up to 461!\n\n## General Changes\n\n- Yet more grammar fixes\n\n## Javascript\n\n- Added quote by DHH about the state of JavaScript in 2020\n\n## Admin chapter\n\n- Removed mention of long deprecated `allow_tags` property descriptor\n- Add warning box to use `format_html` function for enhancing security\n\n## User model chapter\n\n- Added multiple user models\n- Demonstration of proxy models\n\n## Package Used in this Book Appendix\n\n- Out of \"being updated mode\"\n- Reviewed all packages\n- Added new packages\n- Removal of deprecated packages\n\n# Updates until 2020-06-16\n\n## General Changes\n\n- Revised and legible bad code examples!\n- More grammar fixes\n- All use of `reverse()` function now include URL namespaces\n\n## Coding Standards\n\n- Change focus of `Use Explicit Relative Imports` to `Understand Explicit Relative Imports` and removed `Implicit Relative Imports`\n\n## Chapter - Settings and Requirements\n\n- Removed tipbox for `Using django-admin Instead of manage.py`. This advice has been removed from the Django docs\n\n## Chapter - Database Model Best Practices\n\n- Removed link to blog post that used to describe how to use `DateTimeField` with logical deletes\n\n## Chapter - Building APIs with Django Rest Framework\n\n- Added references to OpenAPI and tools\n- Mentioned using vanilla Django for creating APIs\n- Converted package tip for django-tastypie and django-jsonview into a new section for DRF alternatives\n- Added trailing 'r' on `rest_framework.permissions.IsAdminUser`\n\n## Chapter - JavaScript\n\n- Changed section \"Popular JavaScript Frameworks\" to \"Popular JavaScript Approaches\"\n- Added description list for serverside rendering of templates\n- Included alpine.js and turbolinks\n- Added section on JSON encoding for data rendered in the template but consumed by JavaScript\n\n## Chapter - Security\n\n- Corrected typo so PHI is now the acronym for `Protected Health Information`\n\n## Acknowledgements\n\n- Added Bio for Haris Ibrahim\n\n---\n\n# Updates until 2020-06-05\n\n- Included forward by [Will Vincent](https://learndjango.com)\n- Began expanding the async views chapter\n- Made pipenv active again now that they had a formal release\n- Added first half of Appendix A: Chapters mentioned in this book\n\n---\n\n# Updates until 2020-05-29\n\n## General\n\n- Model mommy is now model bakery\n\n## Chapter - Models\n\n- Table layout corrections in chapter 6\n- `BooleanField(null=True)` recommended instead of `NullBooleanField`\n\n## Chapter - FBVs\n\n- Corrected return type for `check_sprinkles` function\n\n## Chapter - Django REST Framework\n\n- Link to sources on how to rate limit\n- Removed material on coreapi because that project has been replaced by openapi\n\n## Chapter - Documentation\n\n- Added myst for rendering markdown in Sphinx\n\n## Chapter - User Model\n\n- Mention that django-authtools doesn't yet work for Django 3\n\n## Chapter - Security\n\n- Ponycheckup is no more. Many thanks to Sasha Romijn for providing such an invaluable\n- Added PyCharm Django Security\n\n---\n\n# Updates until 2020-05-19\n\n## General\n\n- More grammar!\n- Consistent case for `URLConfs`\n\n## Chapter - Environment Setup\n\n- Replaced \"typing\" with \"type casting\", the latter is more explicit\n\n## Chapter - Project Setup\n\n- Added link to Cookiecutter docs\n\n## Chapter - Databases\n\n- Took out the long removed `use_for_related_fields` attribute from manager code example\n\n## Chapter - Templates\n\n- Fix LaTeX escape failure\n\n## Chapter - Security\n\n- Removed Pony Checkup\n\n## Chapter - PaaS\n\n- Added Zappa as an option\n- Took away statement that Elastic Beanstalk was on mod_wsgi and hence no channels\n\n## Chapter - CI\n\n- Added MacOS to Azure Pipelines in feature table\n\n## Chapter - Debugging\n\n- Updated IDE preferences\n\n---\n\n# Updates until 2020-05-13\n\n## General changes\n\n- General grammar and spelling improvements\n- Updated Django version to 3.x\n- Updated Python version to Python 3.8/3.9\n- Removed Appendix giving advice on upgrading from Python 2 to 3\n- Remove mention of Mercurial.\n- Changed `README.rst` to `README.md`\n- `OS X` is now `Mac`\n- References to `django-admin.py` replace with `django-admin`\n- Changed pypi.python.org to pypi.org\n- Removed last vestige of `Twitter Bootstrap` in favor of `Bootstrap`\n- Due to problems with a number of PDF renderers on the Mac URL escaping '#' incorrectly, URLs with '#\" are forwarded through our `feld.to` link shortener. The reader sees the correct URL, but clicking links takes them through feld.to.\n- \"Don't Do This!!\" code examples have new style\n- Use \"README file\" instead of README.md or README.rst\n- Added footer to instruct users where to submit issues\n- Added warnings at the front of chapters which won't be published\n\n## Book crafting process\n\n- LaTeX datestamping now automated. Why didn't we do this years ago?\n- Added placeins LaTex package to the `requirements-latex.yml` file.\n- Updated the book build instructions.\n\n## Note from the authors\n\n- Added Sentry\n- Remove Pinterest from company list\n\n## Introduction\n\n- Removed apocryphal statement by Leonardo Da Vinci\n-\n\n## Chapter - Coding Style\n\n- Added quote from \"Structure and Interpretation of Computer Programs\"\n- Removed duplicate URL\n- Added black\n- Added wemake-python-styleguide\n- Added isort for ordering imports\n- Change JS coding style standard URL to github.com/standard/standard\n\n## Chapter - Environment Setup\n\n- Added mention of poetry, conda, and pipenv\n- Git is now the only tool for version control\n- Added Docker to summary\n- Warn that pip doesn't necessarily come with Python installations on Linux distros\n- Removed mention of `easy_install`\n\n## Chapter - Settings and Requirements\n\n- Use of `json.load` instead of `json.loads`\n\n## Chapter - Django Project Layout\n\n- Added \"Don't Upload Environment Directories To Open Source\" warning box\n- Now calls runserver with the correct settings argument\n- Removed wemake-python-styleguide as a recommendation for Django projects\n\n## Chapter - Fundamentals of App Design\n\n- Removed extra `models.py` from app layout example\n- Added Tom Christie's article for refuting the service layer approach to organizing business logic\n\n## Chapter - Database/Model Best Practices\n\n- Rewrote the enumeration types segment as Django now includes them as part of core\n- Mention `BooleanField` has default of `blank=True`\n- Added Haki Benita's excellent article on bullet proofing Django models\n- `null=True` for `ManyToManyField` is now recommended against as it raises a check warning\n- Custom default Model Managers are no longer forbidden, just an advanced technique to be wary of\n- Removed mention of South as a competing migrations system\n\n## Chapter - More Forms\n\n- Added links to more useful references, removed some outdated ones\n- Switch from JWT library to dj-rest-auth for authentication\n- Remove link to csrf docs\n\n## Chapter - Function- and Class-Based Views\n\n- Removed historical note from Django 1.5 era about not removing function-based views\n- Now using `path()` url route declarations instead of the old `url()` function\n\n## Chapter - Function-Based Views\n\n- Added type annotations to views\n\n## Chapter - Class-Based Views\n\n- Added type annotations to views\n- Flavor model now uses enumeration choices\n- Advice on Mixins inheritance clarified for Python 3\n- Added Serafeim Papastefanos' excellent CBV post to the resources section\n- Added links to more useful references, removed some outdated ones\n\n## Chapter - Asynchronous Views\n\n- Added stub chapter\n\n## Chapter - Templates\n\n- Made Python code example more concise\n- HTML/DTL examples now use 2-space examples\n- Removed Python 2 era mention that `super()` accepts arguments\n\n## Chapter - Template Tags\n\n- Marked django-wysiwyg as deprecated\n\n## Chapter - Jinja2\n\n- Removed statement about maturity of Jinja2 in Django, it's mature now\n- Switched to 2 character tabs\n\n## Chapter - Django REST Framework\n\n- Make more explicit that routers go into `urls.py` modules\n- Mention Randall Degges advice about Usage-Based Plans\n- Mention DRF support for different versioning schemas and link to docs\n- Fixed link to Classy DRF site\n\n## Chapter - Building GraphQL APIs with Graphene\n\n- New chapter!\n\n## Chapter - JavaScript and Django\n\n- Changed the name from **Consuming REST APIs** to **JavaScript and Django**\n- Restructured to be about JavaScript in the Django domain, with REST APIs being a topic\n- Added Vanilla JS as progressive option\n- Moved JQuery to legacy. While, JQuery isn't legacy yet it is on the way to become so\n- Rewrote strengthening JavaScript skills\n- Removed section on `CSRF_COOKIE_HTTPONLY` as it doesn't make Django any more secure, just satisfies some security auditors.\n- No longer recommend JWT as an authentication method\n- No longer excuse turning off CSRF to support JWT\n\n## Chapter - FrankenDjango\n\n- Added https://daniel.feldroy.com/when-to-use-mongodb-with-django.html\n- Made Kevin Systrom a co-founder of Instagram instead of CEO\n\n## Chapter - Django Admin\n\n- Removed `python_2_unicode_compatible` from the example model\n\n## Chapter - Third Party Packages\n\n- Switched from cookiecutter-pypackage to cookiecutter-pylibrary\n- Switched from `.txt` and `.rst` doc extensions to `.md`\n- Removed link to Jeff Knupp's excellent article on open sourcing projects as it is unfortunately out of date\n- For Twine, replaced \"non-ssh\" with \"non-secure\"\n\n## Chapter - Bottlenecks\n\n- Replaced django-johnnycache and django-cache-machine with django-cacheops\n- Removed yslow\n- Change link to Lanyrd search for conference talks to YouTube\n- Removed link to David Cramer's now defunct blog\n- Reference Andrew Brook's excellent book, [The Temple of Django Database Performance](https://spellbookpress.com/books/temple-of-django-database-performance/)\n\n## Chapter - Signals\n\n- Added `on_delete` argument to foreign key example\n\n## Chapter - User Model\n\n- Added methods for differint user types\n\n## Chapter - Testing\n\n- Added assertRaisesMessage\n- Added assertInHTML\n- Added assertURLEqual\n- Removed the defunct requestb.in\n- Added Postman\n- Added interrogate\n\n## Chapter - Documentation\n\n- Removed advising the global installation of Sphinx\n- Switch to recommending Markdown over reStructuredText\n- Provide reStructuredText as the older alternative\n- Remove segment on converting reStructuredText to Markdown\n- Added tipbox for other markdown doc site renderers\n- Added interrogate\n\n## Chapter - Bottlenecks\n\n- Changed `ATOMIC_REQUESTS` to `False`\n\n## Chapter - Security\n\n_Many thanks to our incredibly diligent security reviewers!_\n\n- Fixed borked link to Security Failures Chapter\n- Added warningbox that Let's Encrypt is the most secure option (in progress of being rewritten)\n- Added warningbox that not having HTTPS/SSL is inexescusable in 2020\n- CSP report submitting is optional per the spec\n- Made call for SSL very strident\n- Added cloudflare as a free option for SSL\n- Mentioned big cloud providers for SSL options\n- Remove Sasha Romijn's Pony Checkup. Wonderful tool and we thank her for all those years of supporting Django.\n- ALLOWED_HOSTS and DEBUG=True now throws 400 errors\n- `IceCreamPayment` model's UUID switched from `db_index=True` to `unique=True`\n- Discussion of `SECRET_KEY` now states what can actually occur\n- Added section on not storing unnecessary data which includes credit card, PII, and PHI data\n- Added missing 'N' to the word 'ever'\n- Added section on upgrading password hasher to Argon2\n- Added section on using SRI when loading static assets from external CDNs\n\n## Chapter - Utilities\n\n- Removed `django.utils.six`, we're in Python 3 land now!\n\n## Chapter - Deployment\n\n- Removed mention of `mod_python`\n- Removed reference to very old versions of `mod_wsgi` (3.3 or less)\n- Removed `--no-site-packages` from virtualenv\n\n## Chapter - Continuous Integration\n\n- Removed Python version column from CI-as-a-Service table and replaced with ``operating systems''\n- Added Circle CI, GitHub Actions, Azure Pipelines, and Drone\n\n## Chapter - Debugging\n\n- Removed defunct django-gargoyle package and added django-flags as the plucky newcomer\n\n## Appendix - Packages\n\n- Separated Dependency Management out of Core into own category\n- Added MkDocs\n- Added markdown as option to Sphinx\n- Fixed link to Channels\n\n## Appendix - i18n\n\n- Replace `string_concat` with `format_lazy`\n\n## Appendix - Additional resources\n\n- Added Simple Better Than Complex, apologies to Vitor we didn't include it at launch\n- Added classy Django forms\n- Removed links to our own pages of additional resources\n\n## Appendix - Handling Security Failures\n\n- Removed django-maintenaincemode as it hasn't been updated yet to Django 3\n- Removed django-maintenancemode-2 as it could create a false sense of security. Per the security reviewer: \"that's not a solution, because if your Django installation is compromised, attackers can turn the maintenance mode off again.\"\n\n# Appendix - Security Settings\n\n- Made SMTP as SSL mandatory\n- ALLOWED_HOSTS and DEBUG=True now throws CommandError\n\n# Appendix - Websockets with Channels\n\n- Removed \"Channels Works Better With Python 3.6+\". Django 3 makes Python 3.6 or higher mandatory\n- Fix broken link to Channels' testing documentation\n"
  },
  {
    "path": "code/chapter_00_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass Scoop:\n    def __init__(self):\n        self._is_yummy = True\n"
  },
  {
    "path": "code/chapter_00_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass Scoop:\n    def __init__(self):\n        self._is_yummy = False\n"
  },
  {
    "path": "code/chapter_01_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Stdlib imports\nfrom math import sqrt\nfrom os.path import abspath\n\n# Core Django imports\nfrom django.db import models\nfrom django.utils.translation import gettext_lazy as _\n\n# Third-party app imports\nfrom django_extensions.db.models import TimeStampedModel\n\n# Imports from your apps\nfrom splits.models import BananaSplit\n"
  },
  {
    "path": "code/chapter_01_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# cones/views.py\nfrom django.views.generic import CreateView\n\n# Relative imports of the 'cones' package\nfrom .models import WaffleCone\nfrom .forms import WaffleConeForm\n\n# absolute import from the 'core' package\nfrom core.views import FoodMixin\n\nclass WaffleConeCreateView(FoodMixin, CreateView):\n    model = WaffleCone\n    form_class = WaffleConeForm\n"
  },
  {
    "path": "code/chapter_01_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django import forms\nfrom django.db import models\n"
  },
  {
    "path": "code/chapter_01_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# ANTI-PATTERN: Don't do this!\nfrom django.forms import *\nfrom django.db.models import *\n"
  },
  {
    "path": "code/chapter_01_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# ANTI-PATTERN: Don't do this!\nfrom django.db.models import CharField\nfrom django.forms import CharField\n"
  },
  {
    "path": "code/chapter_01_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db.models import CharField as ModelCharField\nfrom django.forms import CharField as FormCharField\n"
  },
  {
    "path": "code/chapter_01_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\npatterns = [\n    path(route='add/',\n        view=views.add_topping,\n        name='add-topping'),\n    ]\n"
  },
  {
    "path": "code/chapter_01_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\npatterns = [\n    path(route='add/',\n        view=views.add_topping,\n        name='toppings:add_topping'),\n    ]\n"
  },
  {
    "path": "code/chapter_02_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ source ~/.virtualenvs/twoscoops/bin/activate\n"
  },
  {
    "path": "code/chapter_02_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ workon twoscoops\n"
  },
  {
    "path": "code/chapter_03_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ndjango-admin startproject mysite\ncd mysite\ndjango-admin startapp my_app\n"
  },
  {
    "path": "code/chapter_03_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nmysite/\n├── manage.py\n├── my_app\n│   ├── __init__.py\n│   ├── admin.py\n│   ├── apps.py\n│   ├── migrations\n│   │   └── __init__.py\n│   ├── models.py\n│   ├── tests.py\n│   └── views.py\n└── mysite\n    ├── __init__.py\n    ├── asgi.py\n    ├── settings.py\n    ├── urls.py\n    └── wsgi.py\n"
  },
  {
    "path": "code/chapter_03_example_03.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n<repository_root>/\n├── <configuration_root>/\n├── <django_project_root>/\n"
  },
  {
    "path": "code/chapter_03_example_04.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n  icecreamratings_project\n  ├── config/\n  │   ├── settings/\n  │   ├── __init__.py\n  │   ├── asgi.py  \n  │   ├── urls.py\n  │   └── wsgi.py\n  ├── docs/\n  ├── icecreamratings/\n  │   ├── media/  # Development only!\n  │   ├── products/\n  │   ├── profiles/\n  │   ├── ratings/\n  │   ├── static/\n  │   └── templates/\n  ├── .gitignore\n  ├── Makefile\n  ├── README.md\n  ├── manage.py\n  └── requirements.txt\n"
  },
  {
    "path": "code/chapter_03_example_05.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n~/projects/icecreamratings_project/\n~/.envs/icecreamratings/\n"
  },
  {
    "path": "code/chapter_03_example_06.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nc:\\projects\\icecreamratings_project\\\nc:\\envs\\icecreamratings\\\n"
  },
  {
    "path": "code/chapter_03_example_07.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n  ~/.virtualenvs/icecreamratings/\n"
  },
  {
    "path": "code/chapter_03_example_08.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ pip freeze\n"
  },
  {
    "path": "code/chapter_03_example_09.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ pip freeze > requirements.txt\n"
  },
  {
    "path": "code/chapter_03_example_10.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ncookiecutter https://github.com/pydanny/cookiecutter-django\nYou've downloaded /home/quique/.cookiecutters/cookiecutter-django before. Is it okay to delete and re-download it? [yes]: no\nDo you want to re-use the existing version? [yes]: yes\nproject_name [My Awesome Project]: icecreamratings\nproject_slug [icecreamratings]: \ndescription [Behold My Awesome Project!]: Support your Ice Cream Flavour!\nauthor_name [Daniel Roy Greenfeld]:\n<snip for brevity>   \n"
  },
  {
    "path": "code/chapter_04_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# Common modules\nscoops/\n├── __init__.py\n├── admin.py\n├── apps.py\n├── forms.py\n├── management/\n├── migrations/\n├── models.py\n├── templatetags/\n├── tests/\n├── urls.py\n├── views.py\n"
  },
  {
    "path": "code/chapter_04_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# uncommon modules\nscoops/\n├── api/\n├── behaviors.py\n├── constants.py\n├── context_processors.py\n├── decorators.py\n├── db/\n├── exceptions.py\n├── fields.py\n├── factories.py\n├── helpers.py\n├── managers.py\n├── middleware.py\n├── schema.py\n├── signals.py\n├── utils.py\n├── viewmixins.py\n"
  },
  {
    "path": "code/chapter_04_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass UserManager(BaseUserManager):\n    \"\"\"In users/managers.py\"\"\"\n    def create_user(self, email=None, password=None, avatar_url=None):\n        user = self.model(\n            email=email,\n            is_active=True,\n            last_login=timezone.now(),\n            registered_at=timezone.now(),\n            avatar_url=avatar_url\n        )\n        resize_avatar(avatar_url)\n        Ticket.objects.create_ticket(user)\n        return user\n\nclass TicketManager(models.manager):\n    \"\"\"In tasks/managers.py\"\"\"\n    def create_ticket(self, user: User):\n        ticket = self.model(user=user)\n        send_ticket_to_guest_checkin(ticket)\n        return ticket\n"
  },
  {
    "path": "code/chapter_04_example_04.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# Service layer example\nscoops/\n├── api/\n├── models.py\n├── services.py  # Service layer location for business logic\n├── selectors.py  # Service layer location for queries\n├── tests/\n"
  },
  {
    "path": "code/chapter_04_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# In users/services.py\nfrom .models import User\nfrom tickets.models import Ticket, send_ticket_to_guest_checkin\n\ndef create_user(email: str, password: str, avatar_url: str) -> User:\n    user = User(\n        email=email,\n        password=password,\n        avatar_url=avatar_url\n    )\n    user.full_clean()\n    user.resize_avatar()\n    user.save()\n\n    ticket = Ticket(user=user)\n    send_ticket_to_guest_checkin(ticket)\n    return user\n"
  },
  {
    "path": "code/chapter_05_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nsettings/\n├── __init__.py\n├── base.py\n├── local.py\n├── staging.py\n├── test.py\n├── production.py\n"
  },
  {
    "path": "code/chapter_05_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n  python manage.py shell --settings=config.settings.local\n"
  },
  {
    "path": "code/chapter_05_example_03.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npython manage.py runserver --settings=config.settings.local\n"
  },
  {
    "path": "code/chapter_05_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom .base import *\n\nDEBUG = True\n\nEMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'\n\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': 'twoscoops',\n        'HOST': 'localhost',\n    }\n}\n\nINSTALLED_APPS += ['debug_toolbar', ]\n"
  },
  {
    "path": "code/chapter_05_example_05.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npython manage.py runserver --settings=config.settings.local\n"
  },
  {
    "path": "code/chapter_05_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/local_pydanny.py\nfrom .local import *\n\n# Set short cache timeout\nCACHE_TIMEOUT = 30\n"
  },
  {
    "path": "code/chapter_05_example_07.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nsettings/\n    __init__.py\n    base.py\n    local_audreyr.py\n    local_pydanny.py\n    local.py\n    staging.py\n    test.py\n    production.py\n"
  },
  {
    "path": "code/chapter_05_example_08.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nexport SOME_SECRET_KEY=1c3-cr3am-15-yummy\nexport AUDREY_FREEZER_KEY=y34h-r1ght-d0nt-t0uch-my-1c3-cr34m\n"
  },
  {
    "path": "code/chapter_05_example_09.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n> setx SOME_SECRET_KEY 1c3-cr3am-15-yummy\n"
  },
  {
    "path": "code/chapter_05_example_10.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n[Environment]::SetEnvironmentVariable('SOME_SECRET_KEY',\n                                    '1c3-cr3am-15-yummy', 'User')\n[Environment]::SetEnvironmentVariable('AUDREY_FREEZER_KEY',\n                    'y34h-r1ght-d0nt-t0uch-my-1c3-cr34m', 'User')\n"
  },
  {
    "path": "code/chapter_05_example_11.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n[Environment]::SetEnvironmentVariable('SOME_SECRET_KEY',\n                                '1c3-cr3am-15-yummy', 'Machine')\n[Environment]::SetEnvironmentVariable('AUDREY_FREEZER_KEY',\n                'y34h-r1ght-d0nt-t0uch-my-1c3-cr34m', 'Machine')\n"
  },
  {
    "path": "code/chapter_05_example_12.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nunset SOME_SECRET_KEY\nunset AUDREY_FREEZER_KEY\n"
  },
  {
    "path": "code/chapter_05_example_13.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n[Environment]::UnsetEnvironmentVariable('SOME_SECRET_KEY', 'User')\n[Environment]::UnsetEnvironmentVariable('AUDREY_FREEZER_KEY', 'User')\n"
  },
  {
    "path": "code/chapter_05_example_14.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> import os\n>>> os.environ['SOME_SECRET_KEY']\n'1c3-cr3am-15-yummy'\n"
  },
  {
    "path": "code/chapter_05_example_15.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Top of settings/production.py\nimport os\nSOME_SECRET_KEY = os.environ['SOME_SECRET_KEY']\n"
  },
  {
    "path": "code/chapter_05_example_16.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/base.py\nimport os\n\n# Normally you should not import ANYTHING from Django directly\n# into your settings, but ImproperlyConfigured is an exception.\nfrom django.core.exceptions import ImproperlyConfigured\n\ndef get_env_variable(var_name):\n    \"\"\"Get the environment variable or return exception.\"\"\"\n    try:\n        return os.environ[var_name]\n    except KeyError:\n        error_msg = 'Set the {} environment variable'.format(var_name)\n        raise ImproperlyConfigured(error_msg)\n"
  },
  {
    "path": "code/chapter_05_example_17.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nSOME_SECRET_KEY = get_env_variable('SOME_SECRET_KEY')\n"
  },
  {
    "path": "code/chapter_05_example_18.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\ndjango.core.exceptions.ImproperlyConfigured: Set the SOME_SECRET_KEY\nenvironment variable.\n"
  },
  {
    "path": "code/chapter_05_example_19.json",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n{\n  \"FILENAME\": \"secrets.json\",\n  \"SECRET_KEY\": \"I've got a secret!\",\n  \"DATABASES_HOST\": \"127.0.0.1\",\n  \"PORT\": \"5432\"\n}\n"
  },
  {
    "path": "code/chapter_05_example_20.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/base.py\nimport json\n\n# Normally you should not import ANYTHING from Django directly\n# into your settings, but ImproperlyConfigured is an exception.\nfrom django.core.exceptions import ImproperlyConfigured\n\n# JSON-based secrets module\nwith open('secrets.json') as f:\n    secrets = json.load(f)\n\ndef get_secret(setting, secrets=secrets):\n    '''Get the secret variable or return explicit exception.'''\n    try:\n        return secrets[setting]\n    except KeyError:\n        error_msg = 'Set the {0} environment variable'.format(setting)\n        raise ImproperlyConfigured(error_msg)\n\nSECRET_KEY = get_secret('SECRET_KEY')\n"
  },
  {
    "path": "code/chapter_05_example_21.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nrequirements/\n├── base.txt\n├── local.txt\n├── staging.txt\n├── production.txt\n"
  },
  {
    "path": "code/chapter_05_example_22.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nDjango==3.2.0\npsycopg2-binary==2.8.8\ndjangorestframework==3.11.0\n"
  },
  {
    "path": "code/chapter_05_example_23.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n-r base.txt # includes the base.txt requirements file\n\ncoverage==5.1\ndjango-debug-toolbar==2.2\n"
  },
  {
    "path": "code/chapter_05_example_24.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n-r base.txt # includes the base.txt requirements file\n\ncoverage==5.1\n"
  },
  {
    "path": "code/chapter_05_example_25.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n-r base.txt # includes the base.txt requirements file\n"
  },
  {
    "path": "code/chapter_05_example_26.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npip install -r requirements/local.txt\n"
  },
  {
    "path": "code/chapter_05_example_27.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npip install -r requirements/production.txt\n"
  },
  {
    "path": "code/chapter_05_example_28.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/base.py\n\n# Configuring MEDIA_ROOT\n# DON’T DO THIS! Hardcoded to just one user's preferences\nMEDIA_ROOT = '/Users/pydanny/twoscoops_project/media'\n\n# Configuring STATIC_ROOT\n# DON’T DO THIS! Hardcoded to just one user's preferences\nSTATIC_ROOT = '/Users/pydanny/twoscoops_project/collected_static'\n\n# Configuring STATICFILES_DIRS\n# DON’T DO THIS! Hardcoded to just one user's preferences\nSTATICFILES_DIRS = ['/Users/pydanny/twoscoops_project/static']\n\n# Configuring TEMPLATES\n# DON’T DO THIS! Hardcoded to just one user's preferences\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        DIRS: ['/Users/pydanny/twoscoops_project/templates',]\n    },\n]\n"
  },
  {
    "path": "code/chapter_05_example_29.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# At the top of settings/base.py\nfrom pathlib import Path\n\nBASE_DIR = Path(__file__).resolve().parent.parent.parent\nMEDIA_ROOT = BASE_DIR / 'media'\nSTATIC_ROOT = BASE_DIR / 'static_root'\nSTATICFILES_DIRS = [BASE_DIR / 'static']\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [BASE_DIR / 'templates']\n    },\n]\n"
  },
  {
    "path": "code/chapter_05_example_30.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# At the top of settings/base.py\nfrom os.path import abspath, dirname, join\n\ndef root(*dirs):\n    base_dir = join(dirname(__file__), '..', '..')\n    return abspath(join(base_dir, *dirs))\n\nBASE_DIR = root()\nMEDIA_ROOT = root('media')\nSTATIC_ROOT = root('static_root')\nSTATICFILES_DIRS = [root('static')]\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [root('templates')],\n    },\n]\n"
  },
  {
    "path": "code/chapter_06_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db import models\n\nclass TimeStampedModel(models.Model):\n    \"\"\"\n    An abstract base class model that provides self-\n    updating ``created`` and ``modified`` fields.\n    \"\"\"\n    created = models.DateTimeField(auto_now_add=True)\n    modified = models.DateTimeField(auto_now=True)\n\n    class Meta:\n        abstract = True\n"
  },
  {
    "path": "code/chapter_06_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass Meta:\n    abstract = True\n"
  },
  {
    "path": "code/chapter_06_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/models.py\nfrom django.db import models\n\nfrom core.models import TimeStampedModel\n\nclass Flavor(TimeStampedModel):\n    title = models.CharField(max_length=200)\n"
  },
  {
    "path": "code/chapter_06_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db import migrations, models\n\ndef add_cones(apps, schema_editor):\n    Scoop = apps.get_model('scoop', 'Scoop')\n    Cone = apps.get_model('cone', 'Cone')\n\n    for scoop in Scoop.objects.all():\n        Cone.objects.create(\n            scoop=scoop,\n            style='sugar'\n        )\n\nclass Migration(migrations.Migration):\n\n    initial = True\n\n    dependencies = [\n        ('scoop', '0051_auto_20670724'),\n    ]\n\n    operations = [\n        migrations.CreateModel(\n            name='Cone',\n            fields=[\n                ('id', models.AutoField(auto_created=True, primary_key=True,\n                    serialize=False, verbose_name='ID')),\n                ('style', models.CharField(max_length=10),\n                    choices=[('sugar', 'Sugar'), ('waffle', 'Waffle')]),\n                ('scoop', models.OneToOneField(null=True, to='scoop.Scoop'\n                    on_delete=django.db.models.deletion.SET_NULL, )),\n            ],\n        ),\n        # RunPython.noop does nothing but allows reverse migrations to occur\n        migrations.RunPython(add_cones, migrations.RunPython.noop)\n    ]\n"
  },
  {
    "path": "code/chapter_06_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# orders/models.py\nfrom django.db import models\n\nclass IceCreamOrder(models.Model):\n    FLAVOR_CHOCOLATE = 'ch'\n    FLAVOR_VANILLA = 'vn'\n    FLAVOR_STRAWBERRY = 'st'\n    FLAVOR_CHUNKY_MUNKY = 'cm'\n\n    FLAVOR_CHOICES = (\n        (FLAVOR_CHOCOLATE, 'Chocolate'),\n        (FLAVOR_VANILLA, 'Vanilla'),\n        (FLAVOR_STRAWBERRY, 'Strawberry'),\n        (FLAVOR_CHUNKY_MUNKY, 'Chunky Munky')\n    )\n\n    flavor = models.CharField(\n        max_length=2,\n        choices=FLAVOR_CHOICES\n    )\n"
  },
  {
    "path": "code/chapter_06_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from orders.models import IceCreamOrder\n>>> IceCreamOrder.objects.filter(flavor=IceCreamOrder.FLAVOR_CHOCOLATE)\n[<icecreamorder: 35>, <icecreamorder: 42>, <icecreamorder: 49>]\n"
  },
  {
    "path": "code/chapter_06_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db import models\n\nclass IceCreamOrder(models.Model):\n    class Flavors(models.TextChoices):\n        CHOCOLATE = 'ch', 'Chocolate'\n        VANILLA = 'vn', 'Vanilla'\n        STRAWBERRY = 'st', 'Strawberry'\n        CHUNKY_MUNKY = 'cm', 'Chunky Munky'\n\n    flavor = models.CharField(\n        max_length=2,\n        choices=Flavors.choices\n    )\n"
  },
  {
    "path": "code/chapter_06_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from orders.models import IceCreamOrder\n>>> IceCreamOrder.objects.filter(flavor=IceCreamOrder.Flavors.CHOCOLATE)\n[<icecreamorder: 35>, <icecreamorder: 42>, <icecreamorder: 49>]\n"
  },
  {
    "path": "code/chapter_06_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db import models\nfrom django.utils import timezone\n\nclass PublishedManager(models.Manager):\n\n    def published(self, **kwargs):\n        return self.filter(pub_date__lte=timezone.now(), **kwargs)\n\nclass FlavorReview(models.Model):\n    review = models.CharField(max_length=255)\n    pub_date = models.DateTimeField()\n\n    # add our custom model manager\n    objects = PublishedManager()\n"
  },
  {
    "path": "code/chapter_06_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from reviews.models import FlavorReview\n>>> FlavorReview.objects.count()\n35\n>>> FlavorReview.objects.published().count()\n31\n"
  },
  {
    "path": "code/chapter_06_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from reviews.models import FlavorReview\n>>> FlavorReview.objects.filter().count()\n35\n>>> FlavorReview.published.filter().count()\n31\n"
  },
  {
    "path": "code/chapter_07_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.core.exceptions import ObjectDoesNotExist\n\nfrom flavors.models import Flavor\nfrom store.exceptions import OutOfStock\n\ndef list_flavor_line_item(sku):\n    try:\n        return Flavor.objects.get(sku=sku, quantity__gt=0)\n    except Flavor.DoesNotExist:\n        msg = 'We are out of {0}'.format(sku)\n        raise OutOfStock(msg)\n\ndef list_any_line_item(model, sku):\n    try:\n        return model.objects.get(sku=sku, quantity__gt=0)\n    except ObjectDoesNotExist:\n        msg = 'We are out of {0}'.format(sku)\n        raise OutOfStock(msg)\n"
  },
  {
    "path": "code/chapter_07_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom flavors.models import Flavor\nfrom store.exceptions import OutOfStock, CorruptedDatabase\n\ndef list_flavor_line_item(sku):\n    try:\n        return Flavor.objects.get(sku=sku, quantity__gt=0)\n    except Flavor.DoesNotExist:\n        msg = 'We are out of {}'.format(sku)\n        raise OutOfStock(msg)\n    except Flavor.MultipleObjectsReturned:\n        msg = 'Multiple items have SKU {}. Please fix!'.format(sku)\n        raise CorruptedDatabase(msg)\n"
  },
  {
    "path": "code/chapter_07_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Don't do this!\nfrom django.db.models import Q\n\nfrom promos.models import Promo\n\ndef fun_function(name=None):\n    \"\"\"Find working ice cream promo\"\"\"\n    # Too much query chaining makes code go off the screen or page. Not good.\n    return Promo.objects.active().filter(Q(name__startswith=name)|Q(description__icontains=name)).exclude(status='melted')\n"
  },
  {
    "path": "code/chapter_07_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Do this!\nfrom django.db.models import Q\n\nfrom promos.models import Promo\n\ndef fun_function(name=None):\n    \"\"\"Find working ice cream promo\"\"\"\n    results = Promo.objects.active()\n    results = results.filter(\n                Q(name__startswith=name) |\n                Q(description__icontains=name)\n            )\n    results = results.exclude(status='melted')\n    results = results.select_related('flavors')\n    return results\n"
  },
  {
    "path": "code/chapter_07_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Do this!\nfrom django.db.models import Q\n\nfrom promos.models import Promo\n\ndef fun_function(name=None):\n  \"\"\"Find working ice cream promo\"\"\"\n  qs = (Promo\n          .objects\n          .active()\n          .filter(\n              Q(name__startswith=name) |\n              Q(description__icontains=name)\n          )\n          .exclude(status='melted')\n          .select_related('flavors')\n      )\n    return qs\n"
  },
  {
    "path": "code/chapter_07_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\ndef fun_function(name=None):\n    \"\"\"Find working ice cream promo\"\"\"\n    qs = (\n        Promo\n        .objects\n        .active()\n        # .filter(\n        #     Q(name__startswith=name) |\n        #     Q(description__icontains=name)\n        # )\n        # .exclude(status='melted')\n        # .select_related('flavors')\n    )\n    breakpoint()\n    return qs\n"
  },
  {
    "path": "code/chapter_07_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Don't do this!\nfrom models.customers import Customer\n\ncustomers = []\nfor customer in Customer.objects.iterator():\n    if customer.scoops_ordered > customer.store_visits:\n        customers.append(customer)\n"
  },
  {
    "path": "code/chapter_07_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db.models import F\n\nfrom models.customers import Customer\n\ncustomers = Customer.objects.filter(scoops_ordered__gt=F('store_visits'))\n"
  },
  {
    "path": "code/chapter_07_example_09.sql",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nSELECT * from customers_customer where scoops_ordered > store_visits\n"
  },
  {
    "path": "code/chapter_07_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/base.py\n\nDATABASES = {\n    'default': {\n        # ...\n        'ATOMIC_REQUESTS': True,\n    },\n}\n"
  },
  {
    "path": "code/chapter_07_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/views.py\n\nfrom django.db import transaction\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404\nfrom django.utils import timezone\n\nfrom .models import Flavor\n\n@transaction.non_atomic_requests\ndef posting_flavor_status(request, pk, status):\n    flavor = get_object_or_404(Flavor, pk=pk)\n\n    # This will execute in autocommit mode (Django's default).\n    flavor.latest_status_change_attempt = timezone.now()\n    flavor.save()\n\n    with transaction.atomic():\n        # This code executes inside a transaction.\n        flavor.status = status\n        flavor.latest_status_change_success = timezone.now()\n        flavor.save()\n        return HttpResponse('Hooray')\n\n    # If the transaction fails, return the appropriate status\n    return HttpResponse('Sadness', status_code=400)\n"
  },
  {
    "path": "code/chapter_08_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Don't do this!\nfrom django.urls import path\nfrom django.views.generic import DetailView\n\nfrom tastings.models import Tasting\n\nurlpatterns = [\n    path('<int:pk>',\n        DetailView.as_view(\n            model=Tasting,\n            template_name='tastings/detail.html'),\n        name='detail'),\n    path('<int:pk>/results/',\n        DetailView.as_view(\n            model=Tasting,\n            template_name='tastings/results.html'),\n        name='results'),\n]\n"
  },
  {
    "path": "code/chapter_08_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.urls import reverse\nfrom django.views.generic import ListView, DetailView, UpdateView\n\nfrom .models import Tasting\n\nclass TasteListView(ListView):\n    model = Tasting\n\nclass TasteDetailView(DetailView):\n    model = Tasting\n\nclass TasteResultsView(TasteDetailView):\n    template_name = 'tastings/results.html'\n\nclass TasteUpdateView(UpdateView):\n    model = Tasting\n\n    def get_success_url(self):\n        return reverse('tastings:detail',\n            kwargs={'pk': self.object.pk})\n"
  },
  {
    "path": "code/chapter_08_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.urls import path\n\nfrom . import views\n\nurlpatterns = [\n    path(\n        route='',\n        view=views.TasteListView.as_view(),\n        name='list'\n    ),\n    path(\n        route='<int:pk>/',\n        view=views.TasteDetailView.as_view(),\n        name='detail'\n    ),\n    path(\n        route='<int:pk>/results/',\n        view=views.TasteResultsView.as_view(),\n        name='results'\n    ),\n    path(\n        route='<int:pk>/update/',\n        view=views.TasteUpdateView.as_view(),\n        name='update'\n    )\n]\n"
  },
  {
    "path": "code/chapter_08_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nurlpatterns += [\n    path('tastings/', include('tastings.urls', namespace='tastings')),\n]\n"
  },
  {
    "path": "code/chapter_08_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# tastings/views.py snippet\nclass TasteUpdateView(UpdateView):\n    model = Tasting\n\n    def get_success_url(self):\n        return reverse('tastings:detail',\n            kwargs={'pk': self.object.pk})\n"
  },
  {
    "path": "code/chapter_08_example_06.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends 'base.html' %}\n\n{% block title %}Tastings{% endblock title %}\n\n{% block content %}\n<ul>\n  {% for taste in tastings %}\n    <li>\n      <a href=\"{% url 'tastings:detail' taste.pk %}\">{{ taste.title }}</a>\n      <small>\n        (<a href=\"{% url 'tastings:update' taste.pk %}\">update</a>)\n      </small>\n    </li>\n  {% endfor %}\n</ul>\n{% endblock content %}\n"
  },
  {
    "path": "code/chapter_08_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# urls.py at root of project\nurlpatterns += [\n    path('contact/', include('contactmonger.urls',\n                                        namespace='contactmonger')),\n    path('report-problem/', include('contactapp.urls',\n                                            namespace='contactapp')),\n]\n"
  },
  {
    "path": "code/chapter_08_example_08.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends \"base.html\" %}\n{% block title %}Contact{% endblock title %}\n{% block content %}\n<p>\n  <a href=\"{% url 'contactmonger:create' %}\">Contact Us</a>\n</p>\n<p>\n  <a href=\"{% url 'contactapp:report' %}\">Report a Problem</a>\n</p>\n{% endblock content %}\n"
  },
  {
    "path": "code/chapter_08_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Django FBV as a function\nHttpResponse = view(HttpRequest)\n\n# Deciphered into basic math (remember functions from algebra?)\ny = f(x)\n\n# ... and then translated into a CBV example\nHttpResponse = View.as_view()(HttpRequest)\n"
  },
  {
    "path": "code/chapter_08_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.http import HttpResponse\nfrom django.views.generic import View\n\n# The simplest FBV\ndef simplest_view(request):\n    # Business logic goes here\n    return HttpResponse('FBV')\n\n# The simplest CBV\nclass SimplestView(View):\n    def get(self, request, *args, **kwargs):\n        # Business logic goes here\n        return HttpResponse('CBV')\n"
  },
  {
    "path": "code/chapter_08_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Don't do this!\ndef ice_cream_store_display(request, store_id):\n    store = get_object_or_404(Store, id=store_id)\n    date = timezone.now()\n    return render(request, 'melted_ice_cream_report.html', locals())\n"
  },
  {
    "path": "code/chapter_08_example_12.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Don't do this!\ndef ice_cream_store_display(request, store_id):\n    store = get_object_or_404(Store, id=store_id)\n    now = timezone.now()\n    return render(request, 'melted_ice_cream_report.html', locals())\n"
  },
  {
    "path": "code/chapter_08_example_13.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\ndef ice_cream_store_display(request, store_id):\n    return render(\n        request,\n        'melted_ice_cream_report.html',\n        {\n            'store': get_object_or_404(Store, id=store_id),\n            'now': timezone.now()\n        }\n    )\n"
  },
  {
    "path": "code/chapter_09_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.core.exceptions import PermissionDenied\nfrom django.http import HttpRequest\n\ndef check_sprinkle_rights(request: HttpRequest) -> HttpRequest:\n    if request.user.can_sprinkle or request.user.is_staff:\n        return request\n\n    # Return a HTTP 403 back to the user\n    raise PermissionDenied\n"
  },
  {
    "path": "code/chapter_09_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.core.exceptions import PermissionDenied\nfrom django.http import HttpRequest, HttpResponse\n\ndef check_sprinkles(request: HttpRequest) -> HttpRequest:\n    if request.user.can_sprinkle or request.user.is_staff:\n        # By adding this value here it means our display templates\n        #   can be more generic. We don't need to have\n        #   {% if request.user.can_sprinkle or request.user.is_staff %}\n        #   instead just using\n        #   {% if request.can_sprinkle %}\n        request.can_sprinkle = True\n        return request\n\n    # Return a HTTP 403 back to the user\n    raise PermissionDenied\n"
  },
  {
    "path": "code/chapter_09_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# sprinkles/views.py\nfrom django.shortcuts import get_object_or_404\nfrom django.shortcuts import render\nfrom django.http import HttpRequest, HttpResponse\n\nfrom .models import Sprinkle\nfrom .utils import check_sprinkles\n\ndef sprinkle_list(request: HttpRequest) -> HttpResponse:\n    \"\"\"Standard list view\"\"\"\n\n    request = check_sprinkles(request)\n\n    return render(request,\n        \"sprinkles/sprinkle_list.html\",\n        {\"sprinkles\": Sprinkle.objects.all()})\n\ndef sprinkle_detail(request: HttpRequest, pk: int) -> HttpResponse:\n    \"\"\"Standard detail view\"\"\"\n\n    request = check_sprinkles(request)\n\n    sprinkle = get_object_or_404(Sprinkle, pk=pk)\n\n    return render(request, \"sprinkles/sprinkle_detail.html\",\n        {\"sprinkle\": sprinkle})\n\ndef sprinkle_preview(request: HttpRequest) -> HttpResponse:\n    \"\"\"Preview of new sprinkle, but without the\n            check_sprinkles function being used.\n    \"\"\"\n    sprinkle = Sprinkle.objects.all()\n    return render(request,\n        \"sprinkles/sprinkle_preview.html\",\n        {\"sprinkle\": sprinkle})\n"
  },
  {
    "path": "code/chapter_09_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.views.generic import DetailView\n\nfrom .models import Sprinkle\nfrom .utils import check_sprinkles\n\nclass SprinkleDetail(DetailView):\n    \"\"\"Standard detail view\"\"\"\n\n    model = Sprinkle\n\n    def dispatch(self, request, *args, **kwargs):\n        request = check_sprinkles(request)\n        return super().dispatch(request, *args, **kwargs)\n"
  },
  {
    "path": "code/chapter_09_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nimport functools\n\ndef decorator(view_func):\n    @functools.wraps(view_func)\n    def new_view_func(request, *args, **kwargs):\n        # You can modify the request (HttpRequest) object here.\n        response = view_func(request, *args, **kwargs)\n        # You can modify the response (HttpResponse) object here.\n        return response\n    return new_view_func\n"
  },
  {
    "path": "code/chapter_09_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# sprinkles/decorators.py\nimport functools\n\nfrom . import utils\n\n# based off the decorator template from the previous example\ndef check_sprinkles(view_func):\n    \"\"\"Check if a user can add sprinkles\"\"\"\n    @functools.wraps(view_func)\n    def new_view_func(request, *args, **kwargs):\n        # Act on the request object with utils.can_sprinkle()\n        request = utils.can_sprinkle(request)\n\n        # Call the view function\n        response = view_func(request, *args, **kwargs)\n\n        # Return the HttpResponse object\n        return response\n    return new_view_func\n"
  },
  {
    "path": "code/chapter_09_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# sprinkles/views.py\nfrom django.shortcuts import get_object_or_404, render\n\nfrom .decorators import check_sprinkles\nfrom .models import Sprinkle\n\n# Attach the decorator to the view\n@check_sprinkles\ndef sprinkle_detail(request: HttpRequest, pk: int) -> HttpResponse:\n    \"\"\"Standard detail view\"\"\"\n\n    sprinkle = get_object_or_404(Sprinkle, pk=pk)\n\n    return render(request, \"sprinkles/sprinkle_detail.html\",\n        {\"sprinkle\": sprinkle})\n"
  },
  {
    "path": "code/chapter_10_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.views.generic import TemplateView\n\nclass FreshFruitMixin:\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context[\"has_fresh_fruit\"] = True\n        return context\n\nclass FruityFlavorView(FreshFruitMixin, TemplateView):\n    template_name = \"fruity_flavor.html\"\n"
  },
  {
    "path": "code/chapter_10_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/views.py\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import DetailView\n\nfrom .models import Flavor\n\nclass FlavorDetailView(LoginRequiredMixin, DetailView):\n    model = Flavor\n"
  },
  {
    "path": "code/chapter_10_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import CreateView\n\nfrom .models import Flavor\n\nclass FlavorCreateView(LoginRequiredMixin, CreateView):\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n\n    def form_valid(self, form):\n        # Do custom logic here\n        return super().form_valid(form)\n"
  },
  {
    "path": "code/chapter_10_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import CreateView\n\nfrom .models import Flavor\n\nclass FlavorCreateView(LoginRequiredMixin, CreateView):\n    model = Flavor\n\n    def form_invalid(self, form):\n        # Do custom logic here\n        return super().form_invalid(form)\n"
  },
  {
    "path": "code/chapter_10_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.utils.functional import cached_property\nfrom django.views.generic import UpdateView, TemplateView\n\nfrom .models import Flavor\nfrom .tasks import update_user_who_favorited\n\nclass FavoriteMixin:\n\n    @cached_property\n    def likes_and_favorites(self):\n        \"\"\"Returns a dictionary of likes and favorites\"\"\"\n        likes = self.object.likes()\n        favorites = self.object.favorites()\n        return {\n            \"likes\": likes,\n            \"favorites\": favorites,\n            \"favorites_count\": favorites.count(),\n\n        }\n\nclass FlavorUpdateView(LoginRequiredMixin, FavoriteMixin, UpdateView):\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n\n    def form_valid(self, form):\n        update_user_who_favorited(\n            instance=self.object,\n            favorites=self.likes_and_favorites['favorites']\n        )\n        return super().form_valid(form)\n\nclass FlavorDetailView(LoginRequiredMixin, FavoriteMixin, TemplateView):\n    model = Flavor\n"
  },
  {
    "path": "code/chapter_10_example_06.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# flavors/base.html #}\n{% extends \"base.html\" %}\n\n{% block likes_and_favorites %}\n<ul>\n  <li>Likes: {{ view.likes_and_favorites.likes }}</li>\n  <li>Favorites: {{ view.likes_and_favorites.favorites_count }}</li>\n</ul>\n{% endblock likes_and_favorites %}\n"
  },
  {
    "path": "code/chapter_10_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/models.py\nfrom django.db import models\nfrom django.urls import reverse\n\nclass Flavor(models.Model):\n    class Scoops(models.IntegerChoices):\n        SCOOPS_0 = 0\n        SCOOPS_1 = 1\n\n    title = models.CharField(max_length=255)\n    slug = models.SlugField(unique=True)\n    scoops_remaining = models.IntegerField(choices=Scoops.choices,\n        default=Scoops.SCOOPS_0)\n\n    def get_absolute_url(self):\n        return reverse(\"flavors:detail\", kwargs={\"slug\": self.slug})\n"
  },
  {
    "path": "code/chapter_10_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/views.py\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import CreateView, DetailView, UpdateView\n\nfrom .models import Flavor\n\nclass FlavorCreateView(LoginRequiredMixin, CreateView):\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n\nclass FlavorUpdateView(LoginRequiredMixin, UpdateView):\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n\nclass FlavorDetailView(DetailView):\n    model = Flavor\n"
  },
  {
    "path": "code/chapter_10_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/views.py\nfrom django.contrib import messages\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import CreateView, DetailView, UpdateView\n\nfrom .models import Flavor\n\nclass FlavorActionMixin:\n\n    fields = ['title', 'slug', 'scoops_remaining']\n\n    @property\n    def success_msg(self):\n        return NotImplemented\n\n    def form_valid(self, form):\n        messages.info(self.request, self.success_msg)\n        return super().form_valid(form)\n\nclass FlavorCreateView(LoginRequiredMixin, FlavorActionMixin,\n                        CreateView):\n    model = Flavor\n    success_msg = \"Flavor created!\"\n\nclass FlavorUpdateView(LoginRequiredMixin, FlavorActionMixin,\n                        UpdateView):\n    model = Flavor\n    success_msg = \"Flavor updated!\"\n\nclass FlavorDetailView(DetailView):\n    model = Flavor\n"
  },
  {
    "path": "code/chapter_10_example_10.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% if messages %}\n    <ul class=\"messages\">\n        {% for message in messages %}\n        <li id=\"message_{{ forloop.counter }}\"\n            {% if message.tags %} class=\"{{ message.tags }}\"\n                {% endif %}>\n            {{ message }}\n        </li>\n        {% endfor %}\n    </ul>\n{% endif %}\n"
  },
  {
    "path": "code/chapter_10_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.views.generic import ListView\n\nfrom .models import Flavor\n\nclass FlavorListView(ListView):\n    model = Flavor\n\n    def get_queryset(self):\n        # Fetch the queryset from the parent get_queryset\n        queryset = super().get_queryset()\n\n        # Get the q GET parameter\n        q = self.request.GET.get(\"q\")\n        if q:\n            # Return a filtered queryset\n            return queryset.filter(title__icontains=q)\n        # Return the base queryset\n        return queryset\n\n"
  },
  {
    "path": "code/chapter_10_example_12.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# templates/flavors/_flavor_search.html #}\n{% comment %}\n    Usage: {% include \"flavors/_flavor_search.html\" %}\n{% endcomment %}\n<form action=\"{% url \"flavor_list\" %}\" method=\"GET\">\n    <input type=\"text\" name=\"q\" />\n    <button type=\"submit\">search</button>\n</form>\n"
  },
  {
    "path": "code/chapter_10_example_13.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.shortcuts import get_object_or_404\nfrom django.shortcuts import render, redirect\nfrom django.views.generic import View\n\nfrom .forms import FlavorForm\nfrom .models import Flavor\n\nclass FlavorView(LoginRequiredMixin, View):\n\n    def get(self, request, *args, **kwargs):\n        # Handles display of the Flavor object\n        flavor = get_object_or_404(Flavor, slug=kwargs['slug'])\n        return render(request,\n            \"flavors/flavor_detail.html\",\n                {\"flavor\": flavor}\n            )\n\n    def post(self, request, *args, **kwargs):\n        # Handles updates of the Flavor object\n        flavor = get_object_or_404(Flavor, slug=kwargs['slug'])\n        form = FlavorForm(request.POST, instance=flavor)\n        if form.is_valid():\n            form.save()\n        return redirect(\"flavors:detail\", flavor.slug)\n"
  },
  {
    "path": "code/chapter_10_example_14.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.http import HttpResponse\nfrom django.shortcuts import get_object_or_404\nfrom django.views.generic import View\n\nfrom .models import Flavor\nfrom .reports import make_flavor_pdf\n\nclass FlavorPDFView(LoginRequiredMixin, View):\n\n    def get(self, request, *args, **kwargs):\n        # Get the flavor\n        flavor = get_object_or_404(Flavor, slug=kwargs['slug'])\n\n        # create the response\n        response = HttpResponse(content_type='application/pdf')\n\n        # generate the PDF stream and attach to the response\n        response = make_flavor_pdf(response, flavor)\n\n        return response\n"
  },
  {
    "path": "code/chapter_11_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/mixins.py\nclass AsyncViewMixin:\n    async def __call__(self):\n        return super().__call__(self)  \n"
  },
  {
    "path": "code/chapter_11_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom asgiref.sync import sync_to_async\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.generic.views import AsyncViewMixin, View\nfrom django.shortcuts import get_object_or_404, render, redirect\n\nfrom core.mixins import AsyncViewMixin\nfrom .forms import FlavorForm\nfrom .models import Flavor\n\nclass FlavorUpdateView(LoginRequiredMixin, AsyncViewMixin, View):\n    def get(self, request, *args, **kwargs):\n        flavor = get_object_or_404(Flavor, slug=slug)   \n        return render(request, \"flavor_form.html\", {\"flavor\": Flavor})\n\n    def post(self, request, *args, **kwargs):\n        form = FlavorForm(request.POST)\n        if form.is_valid():\n            sync_to_async(form.save())\n        else:\n            return render(request, {'form': form}, \"flavor_form.html\")\n        return redirect(\"flavor:detail\")\n"
  },
  {
    "path": "code/chapter_11_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.generic.views import View\nfrom django.http import JsonResponse\nfrom django.shortcuts import get_object_or_404\n\nimport httpx\n\nfrom core.mixins import AsyncViewMixin\n\nclass InvokeMicroserviceView(LoginRequiredMixin, AsyncViewMixin, View):\n\n    def post(self, request, *args, **kwargs):\n        % try:\n        %     async with httpx.AsyncClient() as client:\n        %         response = await client.get(PROMO_SERVICE_URL)\n        %         if response.status_code == httpx.codes.OK:\n        %             context[\"promo\"] = response.json()\n        %         response = await client.get(RECCO_SERVICE_URL)\n        %         if response.status_code == httpx.codes.OK:\n        %             context[\"recco\"] = response.json()\n        % except httpx.RequestError as exc:\n        %     print(f\"An error occurred while requesting {exc.request.url!r}.\")\n        return JsonResponse({})\n"
  },
  {
    "path": "code/chapter_12_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import CreateView, UpdateView\n\nfrom .models import Flavor\n\nclass FlavorCreateView(LoginRequiredMixin, CreateView):\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n\nclass FlavorUpdateView(LoginRequiredMixin, UpdateView):\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n"
  },
  {
    "path": "code/chapter_12_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/validators.py\nfrom django.core.exceptions import ValidationError\n\ndef validate_tasty(value):\n    \"\"\"Raise a ValidationError if the value doesn't start with the\n        word 'Tasty'.\n    \"\"\"\n    if not value.startswith('Tasty'):\n        msg = 'Must start with Tasty'\n        raise ValidationError(msg)\n"
  },
  {
    "path": "code/chapter_12_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/models.py\nfrom django.db import models\n\nfrom .validators import validate_tasty\n\nclass TastyTitleAbstractModel(models.Model):\n\n    title = models.CharField(max_length=255, validators=[validate_tasty])\n\n    class Meta:\n        abstract = True\n"
  },
  {
    "path": "code/chapter_12_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/models.py\nfrom django.db import models\nfrom django.urls import reverse\n\nfrom core.models import TastyTitleAbstractModel\n\nclass Flavor(TastyTitleAbstractModel):\n    slug = models.SlugField()\n    scoops_remaining = models.IntegerField(default=0)\n\n    def get_absolute_url(self):\n        return reverse('flavors:detail', kwargs={'slug': self.slug})\n"
  },
  {
    "path": "code/chapter_12_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/forms.py\nfrom django import forms\n\nfrom .models import Flavor\nfrom core.validators import validate_tasty\n\nclass FlavorForm(forms.ModelForm):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields['title'].validators.append(validate_tasty)\n        self.fields['slug'].validators.append(validate_tasty)\n\n    class Meta:\n        model = Flavor\n        fields = ['title', 'slug']\n"
  },
  {
    "path": "code/chapter_12_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/views.py\nfrom django.contrib import messages\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import CreateView, DetailView, UpdateView\n\nfrom .models import Flavor\nfrom .forms import FlavorForm\n\nclass FlavorActionMixin:\n\n    model = Flavor\n    fields = ['title', 'slug', 'scoops_remaining']\n\n    @property\n    def success_msg(self):\n        return NotImplemented\n\n    def form_valid(self, form):\n        messages.info(self.request, self.success_msg)\n        return super().form_valid(form)\n\nclass FlavorCreateView(LoginRequiredMixin, FlavorActionMixin,\n                            CreateView):\n    success_msg = 'created'\n    # Explicitly attach the FlavorForm class\n    form_class = FlavorForm\n\nclass FlavorUpdateView(LoginRequiredMixin, FlavorActionMixin,\n                            UpdateView):\n    success_msg = 'updated'\n    # Explicitly attach the FlavorForm class\n    form_class = FlavorForm\n\nclass FlavorDetailView(DetailView):\n    model = Flavor\n"
  },
  {
    "path": "code/chapter_12_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/forms.py\nfrom django import forms\n\nfrom flavors.models import Flavor\n\nclass IceCreamOrderForm(forms.Form):\n    \"\"\"Normally done with forms.ModelForm. But we use forms.Form here\n        to demonstrate that these sorts of techniques work on every\n        type of form.\n    \"\"\"\n    slug = forms.ChoiceField(label='Flavor')\n    toppings = forms.CharField()\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        # We dynamically set the choices here rather than\n        # in the flavor field definition. Setting them in\n        # the field definition means status updates won't\n        # be reflected in the form without server restarts.\n        self.fields['slug'].choices = [\n            (x.slug, x.title) for x in Flavor.objects.all()\n        ]\n        # NOTE: We could filter by whether or not a flavor\n        #       has any scoops, but this is an example of\n        #       how to use clean_slug, not filter().\n\n    def clean_slug(self):\n        slug = self.cleaned_data['slug']\n        if Flavor.objects.get(slug=slug).scoops_remaining <= 0:\n            msg = 'Sorry, we are out of that flavor.'\n            raise forms.ValidationError(msg)\n        return slug\n"
  },
  {
    "path": "code/chapter_12_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n    # attach this code to the previous example (12.7)\n    def clean(self):\n        cleaned_data = super().clean()\n        slug = cleaned_data.get('slug', '')\n        toppings = cleaned_data.get('toppings', '')\n\n        # Silly \"too much chocolate\" validation example\n        in_slug = 'chocolate' in slug.lower()\n        in_toppings = 'chocolate' in toppings.lower()\n        if in_slug and in_toppings:\n            msg = 'Your order has too much chocolate.'\n            raise forms.ValidationError(msg)\n        return cleaned_data\n"
  },
  {
    "path": "code/chapter_12_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/models.py\nfrom django.db import models\nfrom django.urls import reverse\n\nclass IceCreamStore(models.Model):\n    title = models.CharField(max_length=100)\n    block_address = models.TextField()\n    phone = models.CharField(max_length=20, blank=True)\n    description = models.TextField(blank=True)\n\n    def get_absolute_url(self):\n        return reverse('stores:store_detail', kwargs={'pk': self.pk})\n"
  },
  {
    "path": "code/chapter_12_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/forms.py\nfrom django import forms\n\nfrom .models import IceCreamStore\n\nclass IceCreamStoreUpdateForm(forms.ModelForm):\n    # Don't do this! Duplication of the model field!\n    phone = forms.CharField(required=True)\n    # Don't do this! Duplication of the model field!\n    description = forms.TextField(required=True)\n\n    class Meta:\n        model = IceCreamStore\n        fields = '__all__'\n"
  },
  {
    "path": "code/chapter_12_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/forms.py\n# Call phone and description from the self.fields dict-like object\nfrom django import forms\n\nfrom .models import IceCreamStore\n\nclass IceCreamStoreUpdateForm(forms.ModelForm):\n\n    class Meta:\n        model = IceCreamStore\n        fields = ['phone', 'description']\n\n    def __init__(self, *args, **kwargs):\n        # Call the original __init__ method before assigning\n        # field overloads\n        super().__init__(*args, **kwargs)\n        self.fields['phone'].required = True\n        self.fields['description'].required = True\n"
  },
  {
    "path": "code/chapter_12_example_12.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/forms.py\nfrom django import forms\n\nfrom .models import IceCreamStore\n\nclass IceCreamStoreCreateForm(forms.ModelForm):\n\n    class Meta:\n        model = IceCreamStore\n        fields = ['title', 'block_address', ]\n\nclass IceCreamStoreUpdateForm(IceCreamStoreCreateForm):\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.fields['phone'].required = True\n        self.fields['description'].required = True\n\n    class Meta(IceCreamStoreCreateForm.Meta):\n        # show all the fields!\n        fields = ['title', 'block_address', 'phone',\n                'description', ]\n"
  },
  {
    "path": "code/chapter_12_example_13.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/views\nfrom django.views.generic import CreateView, UpdateView\n\nfrom .forms import IceCreamStoreCreateForm, IceCreamStoreUpdateForm\nfrom .models import IceCreamStore\n\nclass IceCreamCreateView(CreateView):\n    model = IceCreamStore\n    form_class = IceCreamStoreCreateForm\n\nclass IceCreamUpdateView(UpdateView):\n    model = IceCreamStore\n    form_class = IceCreamStoreUpdateForm\n"
  },
  {
    "path": "code/chapter_12_example_14.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/views.py\nclass TitleSearchMixin:\n\n    def get_queryset(self):\n        # Fetch the queryset from the parent's get_queryset\n        queryset = super().get_queryset()\n\n        # Get the q GET parameter\n        q = self.request.GET.get('q')\n        if q:\n            # return a filtered queryset\n            return queryset.filter(title__icontains=q)\n        # No q is specified so we return queryset\n        return queryset\n"
  },
  {
    "path": "code/chapter_12_example_15.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# add to flavors/views.py\nfrom django.views.generic import ListView\n\nfrom .models import Flavor\nfrom core.views import TitleSearchMixin\n\nclass FlavorListView(TitleSearchMixin, ListView):\n    model = Flavor\n"
  },
  {
    "path": "code/chapter_12_example_16.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# add to stores/views.py\nfrom django.views.generic import ListView\n\nfrom .models import Store\nfrom core.views import TitleSearchMixin\n\nclass IceCreamStoreListView(TitleSearchMixin, ListView):\n    model = Store\n"
  },
  {
    "path": "code/chapter_12_example_17.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# form to go into stores/store_list.html template #}\n<form action=\"\" method=\"GET\">\n    <input type=\"text\" name=\"q\" />\n    <button type=\"submit\">search</button>\n</form>\n"
  },
  {
    "path": "code/chapter_12_example_18.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# form to go into flavors/flavor_list.html template #}\n<form action=\"\" method=\"GET\">\n    <input type=\"text\" name=\"q\" />\n    <button type=\"submit\">search</button>\n</form>\n"
  },
  {
    "path": "code/chapter_13_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nimport csv\n\nfrom django.utils.six import StringIO\n\nfrom .models import Purchase\n\ndef add_csv_purchases(rows):\n\n    rows = StringIO.StringIO(rows)\n    records_added = 0\n\n    # Generate a dict per row, with the first CSV row being the keys\n    for row in csv.DictReader(rows, delimiter=','):\n        # DON'T DO THIS: Tossing unvalidated data into your model.\n        Purchase.objects.create(**row)\n        records_added += 1\n    return records_added\n"
  },
  {
    "path": "code/chapter_13_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nimport csv\n\nfrom django.utils.six import StringIO\n\nfrom django import forms\n\nfrom .models import Purchase, Seller\n\nclass PurchaseForm(forms.ModelForm):\n\n    class Meta:\n        model = Purchase\n        fields = '__all__'\n\n    def clean_seller(self):\n        seller = self.cleaned_data['seller']\n        try:\n            Seller.objects.get(name=seller)\n        except Seller.DoesNotExist:\n            msg = '{0} does not exist in purchase #{1}.'.format(\n                seller,\n                self.cleaned_data['purchase_number']\n            )\n            raise forms.ValidationError(msg)\n        return seller\n\ndef add_csv_purchases(rows):\n\n    rows = StringIO.StringIO(rows)\n\n    records_added = 0\n    errors = []\n    # Generate a dict per row, with the first CSV row being the keys.\n    for row in csv.DictReader(rows, delimiter=','):\n\n        # Bind the row data to the PurchaseForm.\n        form = PurchaseForm(row)\n        # Check to see if the row data is valid.\n        if form.is_valid():\n            # Row data is valid so save the record.\n            form.save()\n            records_added += 1\n        else:\n            errors.append(form.errors)\n\n    return records_added, errors\n\n"
  },
  {
    "path": "code/chapter_13_example_03.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<form action=\"{% url 'flavor_add' %}\" method=\"POST\">\n"
  },
  {
    "path": "code/chapter_13_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django import forms\n\nfrom .models import Taster\n\nclass TasterForm(forms.ModelForm):\n\n    class Meta:\n        model = Taster\n        fields = ['name', 'dreams', 'aspirations']\n\n    def __init__(self, *args, **kwargs):\n        # set the user as an attribute of the form\n        self.user = kwargs.pop('user')\n        super().__init__(*args, **kwargs)\n"
  },
  {
    "path": "code/chapter_13_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.views.generic import UpdateView\n\nfrom .forms import TasterForm\nfrom .models import Taster\n\nclass TasterUpdateView(LoginRequiredMixin, UpdateView):\n    model = Taster\n    form_class = TasterForm\n    success_url = '/someplace/'\n\n    def get_form_kwargs(self):\n        \"\"\"This method is what injects forms with keyword arguments.\"\"\"\n        # grab the current set of form #kwargs\n        kwargs = super().get_form_kwargs()\n        # Update the kwargs with the user_id\n        kwargs['user'] = self.request.user\n        return kwargs\n"
  },
  {
    "path": "code/chapter_13_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/models.py\nfrom django.db import models\n\nclass ModelFormFailureHistory(models.Model):\n    form_data = models.TextField()\n    model_data = models.TextField()\n"
  },
  {
    "path": "code/chapter_13_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/views.py\nimport json\n\nfrom django.contrib import messages\nfrom django.core import serializers\n\nfrom core.models import ModelFormFailureHistory\n\nclass FlavorActionMixin:\n\n    @property\n    def success_msg(self):\n        return NotImplemented\n\n    def form_valid(self, form):\n        messages.info(self.request, self.success_msg)\n        return super().form_valid(form)\n\n    def form_invalid(self, form):\n        \"\"\"Save invalid form and model data for later reference.\"\"\"\n        form_data = json.dumps(form.cleaned_data)\n        # Serialize the form.instance\n        model_data = serializers.serialize('json', [form.instance])\n        # Strip away leading and ending bracket leaving only a dict\n        model_data = model_data[1:-1]\n        ModelFormFailureHistory.objects.create(\n            form_data=form_data,\n            model_data=model_data\n        )\n        return super().form_invalid(form)\n\n"
  },
  {
    "path": "code/chapter_13_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django import forms\n\nclass IceCreamReviewForm(forms.Form):\n    # Rest of tester form goes here\n    ...\n\n    def clean(self):\n        cleaned_data = super().clean()\n        flavor = cleaned_data.get('flavor')\n        age = cleaned_data.get('age')\n\n        if flavor == 'coffee' and age < 3:\n            # Record errors that will be displayed later.\n            msg = 'Coffee Ice Cream is not for Babies.'\n            self.add_error('flavor', msg)\n            self.add_error('age', msg)\n\n        # Always return the full collection of cleaned data.\n        return cleaned_data\n"
  },
  {
    "path": "code/chapter_13_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings.py\nFORM_RENDERER = 'django.forms.renderers.TemplatesSetting'\n\nINSTALLED_APPS = [\n    ...\n    'django.forms',\n    ...\n]\n"
  },
  {
    "path": "code/chapter_13_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/widgets.py\nfrom django.forms.widgets import TextInput\n\nclass IceCreamFlavorInput(TextInput):\n  \"\"\"Ice cream flavors must always end with 'Ice Cream'\"\"\"\n\n    def get_context(self, name, value, attrs):\n        context = super().get_context(name, value, attrs)\n        value = context['widget']['value']\n        if not value.strip().lower().endswith('ice cream'):\n            context['widget']['value'] = '{} Ice Cream'.format(value)\n        return context\n"
  },
  {
    "path": "code/chapter_14_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ntemplates/\n├── base.html\n├── ... (other sitewide templates in here)\n├── freezers/\n│   ├── (\"freezers\" app templates in here)\n"
  },
  {
    "path": "code/chapter_14_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nfreezers/\n├── templates/\n│   ├── freezers/\n│   │   ├── ... (\"freezers\" app templates in here)\ntemplates/\n├── base.html\n├── ... (other sitewide templates in here)\n"
  },
  {
    "path": "code/chapter_14_example_03.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ntemplates/\n├── base.html\n├── dashboard.html # extends base.html\n├── profiles/\n│   ├── profile_detail.html # extends base.html\n│   ├── profile_form.html # extends base.html\n"
  },
  {
    "path": "code/chapter_14_example_04.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ntemplates/\n    base.html\n    dashboard.html # extends base.html\n    profiles/\n        base_profiles.html # extends base.html\n        profile_detail.html # extends base_profiles.html\n        profile_form.html # extends base_profiles.html\n"
  },
  {
    "path": "code/chapter_14_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# vouchers/models.py\nfrom django.db import models\n\n\nfrom .managers import VoucherManager\n\nclass Voucher(models.Model):\n    \"\"\"Vouchers for free pints of ice cream.\"\"\"\n    name = models.CharField(max_length=100)\n    email = models.EmailField()\n    address = models.TextField()\n    birth_date = models.DateField(blank=True)\n    sent = models.DateTimeField(null=True, default=None)\n    redeemed = models.DateTimeField(null=True, default=None)\n\n    objects = VoucherManager()\n"
  },
  {
    "path": "code/chapter_14_example_06.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# templates/vouchers/ages.html #}\n{% extends \"base.html\" %}\n\n{% block content %}\n<table>\n<thead>\n  <tr>\n    <th>Age Bracket</th>\n    <th>Number of Vouchers Issued</th>\n  </tr>\n</thead>\n<tbody>\n  {% for age_bracket in age_brackets %}\n  <tr>\n    <td>{{ age_bracket.title }}</td>\n    <td>{{ age_bracket.count }}</td>\n  </tr>\n  {% endfor %}\n</tbody>\n</table>\n{% endblock content %}\n"
  },
  {
    "path": "code/chapter_14_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# vouchers/managers.py\nfrom django.db import models\nfrom django.utils import timezone\n\nfrom dateutil.relativedelta import relativedelta\n\nclass VoucherManager(models.Manager):\n    def age_breakdown(self):\n        \"\"\"Returns a dict of age brackets/counts.\"\"\"\n        age_brackets = []\n        delta = timezone.now() - relativedelta(years=18)\n        count = self.model.objects.filter(birth_date__gt=delta).count()\n        age_brackets.append(\n            {'title': '0-17', 'count': count}\n        )\n        count = self.model.objects.filter(birth_date__lte=delta).count()\n        age_brackets.append(\n            {'title': '18+', 'count': count}\n        )\n        return age_brackets\n"
  },
  {
    "path": "code/chapter_14_example_08.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<h2>Greenfelds Who Want Ice Cream</h2>\n<ul>\n{% for voucher in voucher_list %}\n  {# Don't do this: conditional filtering in templates #}\n  {% if 'greenfeld' in voucher.name.lower %}\n    <li>{{ voucher.name }}</li>\n  {% endif %}\n{% endfor %}\n</ul>\n\n<h2>Roys Who Want Ice Cream</h2>\n<ul>\n{% for voucher in voucher_list %}\n  {# Don't do this: conditional filtering in templates #}\n  {% if 'roy' in voucher.name.lower %}\n    <li>{{ voucher.name }}</li>\n  {% endif %}\n{% endfor %}\n</ul>\n"
  },
  {
    "path": "code/chapter_14_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# vouchers/views.py\nfrom django.views.generic import TemplateView\n\nfrom .models import Voucher\n\nclass GreenfeldRoyView(TemplateView):\n    template_name = 'vouchers/views_conditional.html'\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context['greenfelds'] = \\\n                Voucher.objects.filter(name__icontains='greenfeld')\n        context['roys'] = Voucher.objects.filter(name__icontains='roy')\n        return context\n"
  },
  {
    "path": "code/chapter_14_example_10.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<h2>Greenfelds Who Want Ice Cream</h2>\n<ul>\n{% for voucher in greenfelds %}\n  <li>{{ voucher.name }}</li>\n{% endfor %}\n</ul>\n\n<h2>Roys Who Want Ice Cream</h2>\n<ul>\n{% for voucher in roys %}\n  <li>{{ voucher.name }}</li>\n{% endfor %}\n</ul>\n"
  },
  {
    "path": "code/chapter_14_example_11.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# list generated via User.objects.all() #}\n<h1>Ice Cream Fans and their favorite flavors.</h1>\n<ul>\n{% for user in user_list %}\n  <li>\n    {{ user.name }}:\n      {# DON'T DO THIS: Generated implicit query per user #}\n      {{ user.flavor.title }}\n      {# DON'T DO THIS: Second implicit query per user!!! #}\n      {{ user.flavor.scoops_remaining }}\n  </li>\n{% endfor %}\n</ul>\n"
  },
  {
    "path": "code/chapter_14_example_12.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% comment %}\nList generated via User.objects.all().select_related('flavor')\n{% endcomment %}\n<h1>Ice Cream Fans and their favorite flavors.</h1>\n<ul>\n{% for user in user_list %}\n    <li>\n        {{ user.name }}:\n        {{ user.flavor.title }}\n        {{ user.flavor.scoops_remaining }}\n    </li>\n{% endfor %}\n</ul>\n"
  },
  {
    "path": "code/chapter_14_example_13.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% comment %}Don't do this! This code bunches everything\ntogether to generate pretty HTML.\n{% endcomment %}\n{% if list_type=='unordered' %}<ul>{% else %}<ol>{% endif %}{% for\nsyrup in syrup_list %}<li class=\"{{ syrup.temperature_type|roomtemp\n}}\"><a href=\"{% url 'syrup_detail' syrup.slug %}\">{% syrup.title %}\n</a></li>{% endfor %}{% if list_type=='unordered' %}</ul>{% else %}\n</ol>{% endif %}\n"
  },
  {
    "path": "code/chapter_14_example_14.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# Use indentation/comments to ensure code quality #}\n{# start of list elements #}\n{% if list_type=='unordered' %}\n  <ul>\n{% else %}\n  <ol>\n{% endif %}\n\n{% for syrup in syrup_list %}\n  <li class=\"{{ syrup.temperature_type|roomtemp }}\">\n    <a href=\"{% url 'syrup_detail' syrup.slug %}\">\n      {% syrup.title %}\n    </a>\n  </li>\n{% endfor %}\n{# end of list elements #}\n{% if list_type=='unordered' %}\n  </ul>\n{% else %}\n  </ol>\n{% endif %}\n"
  },
  {
    "path": "code/chapter_14_example_15.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# simple base.html #}\n{% load static %}\n<html>\n<head>\n  <title>\n    {% block title %}Two Scoops of Django{% endblock title %}\n  </title>\n  {% block stylesheets %}\n  <link rel=\"stylesheet\" type=\"text/css\"\n    href=\"{% static 'css/project.css' %}\">\n  {% endblock stylesheets %}\n</head>\n<body>\n  <div class=\"content\">\n    {% block content %}\n      <h1>Two Scoops</h1>\n    {% endblock content %}\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "code/chapter_14_example_16.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends \"base.html\" %}\n{% load static %}\n{% block title %}About Audrey and Daniel{% endblock title %}\n{% block stylesheets %}\n  {{ block.super }}\n  <link rel=\"stylesheet\" type=\"text/css\"\n    href=\"{% static 'css/about.css' %}\">\n{% endblock stylesheets %}\n{% block content %}\n  {{ block.super }}\n  <h2>About Audrey and Daniel</h2>\n  <p>They enjoy eating ice cream</p>\n{% endblock content %}\n"
  },
  {
    "path": "code/chapter_14_example_17.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<html>\n<head>\n<title>\n  About Audrey and Daniel\n</title>\n<link rel=\"stylesheet\" type=\"text/css\"\n  href=\"/static/css/project.css\">\n<link rel=\"stylesheet\" type=\"text/css\"\n  href=\"/static/css/about.css\">\n</head>\n<body>\n<div class=\"content\">\n  <h1>Two Scoops</h1>\n  <h2>About Audrey and Daniel</h2>\n  <p>They enjoy eating ice cream</p>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "code/chapter_14_example_18.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends \"base.html\" %}\n{% block stylesheets %}\n  {{ block.super }} {# this brings in project.css #}\n  <link rel=\"stylesheet\" type=\"text/css\"\n    href=\"{% static 'css/custom.css' %}\" />\n{% endblock stylesheets %}\n"
  },
  {
    "path": "code/chapter_14_example_19.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends \"base.html\" %}\n{% block stylesheets %}\n  <link rel=\"stylesheet\" type=\"text/css\"\n    href=\"{% static 'css/dashboard.css' %}\" />\n  {% comment %}\n    By not using {{ block.super }}, this block overrides the\n    stylesheet block of base.html\n  {% endcomment %}\n{% endblock stylesheets %}\n"
  },
  {
    "path": "code/chapter_14_example_20.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends \"base.html\" %}\n{% comment %}\n  By not using {% block stylesheets %}, this template inherits the\n  stylesheets block from the base.html parent, in this case the\n  default project.css link.\n{% endcomment %}\n"
  },
  {
    "path": "code/chapter_14_example_21.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{# templates/toppings/topping_list.html #}\n{# Using implicit names, good for code reuse #}\n<ol>\n{% for object in object_list %}\n  <li>{{ object }} </li>\n{% endfor %}\n</ol>\n\n{# Using explicit names, good for object specific code #}\n<ol>\n{% for topping in topping_list %}\n  <li>{{ topping }} </li>\n{% endfor %}\n</ol>\n"
  },
  {
    "path": "code/chapter_14_example_22.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<a href=\"/flavors/\">\n"
  },
  {
    "path": "code/chapter_14_example_23.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<a href=\"{% url 'flavors:list' %}\">\n"
  },
  {
    "path": "code/chapter_14_example_24.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/local.py\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'APP_DIRS': True,\n        'OPTIONS': {\n              'string_if_invalid': 'INVALID EXPRESSION: %s'\n            }\n    },\n]\n"
  },
  {
    "path": "code/chapter_15_example_01.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{% extends \"base.html\" %}\n\n{% load flavors_tags %}\n"
  },
  {
    "path": "code/chapter_15_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings/base.py\nTEMPLATES = [\n    'BACKEND': 'django.template.backends.django.DjangoTemplates',\n    'OPTIONS': {\n        # Don't do this!\n        # It's an evil anti-pattern!\n        'builtins': ['flavors.templatetags.flavors_tags'],\n    },\n]\n"
  },
  {
    "path": "code/chapter_16_example_01.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<div style=\"display:none\">\n    <input type=\"hidden\" name=\"csrfmiddlewaretoken\" value=\"{{ csrf_token }}\">\n</div>\n"
  },
  {
    "path": "code/chapter_16_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/jinja2.py\nfrom django.contrib.staticfiles.storage import staticfiles_storage\nfrom django.template import defaultfilters\nfrom django.urls import reverse\n\nfrom jinja2 import Environment\n\ndef environment(**options):\n    env = Environment(**options)\n    env.globals.update({\n        'static': staticfiles_storage.url,\n        'url': reverse,\n        'dj': defaultfilters\n    })\n    return env\n"
  },
  {
    "path": "code/chapter_16_example_03.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<table><tbody>\n{% for purchase in purchase_list %}\n  <tr>\n    <a href=\"{{ url('purchase:detail', pk=purchase.pk) }}\">\n        {{ purchase.title }}\n    </a>\n  </tr>\n  <tr>{{ dj.date(purchase.created, 'SHORT_DATE_FORMAT') }}</tr>\n  <tr>{{ dj.floatformat(purchase.amount, 2) }}</tr>\n{% endfor %}\n</tbody></table>\n"
  },
  {
    "path": "code/chapter_16_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/mixins.py\nfrom django.template import defaultfilters\n\nclass DjFilterMixin:\n    dj = defaultfilters\n"
  },
  {
    "path": "code/chapter_16_example_05.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<table><tbody>\n{% for purchase in purchase_list %}\n    <tr>\n        <a href=\"{{ url('purchase:detail', pk=purchase.pk) }}\">\n            {{ purchase.title }}\n        </a>\n    </tr>\n    <!-- Call the django.template.defaultfilters functions from the view -->\n    <tr>{{ view.dj.date(purchase.created, 'SHORT_DATE_FORMAT') }}</tr>\n    <tr>{{ view.dj.floatformat(purchase.amount, 2) }}</tr>\n{% endfor %}\n</tbody></table>\n"
  },
  {
    "path": "code/chapter_16_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/jinja2.py\nfrom jinja2 import Environment\n\nimport random\n\ndef environment(**options):\n    env = Environment(**options)\n    env.globals.update({\n        # Runs only on the first template load! The three displays below\n        #   will all present the same number.\n        #   {{ random_once }} {{ random_once }} {{ random_once }}\n        'random_once': random.randint(1, 5)\n        # Can be called repeated as a function in templates. Each call\n        #   returns a random number:\n        #   {{ random() }} {{ random() }} {{ random() }}\n        'random': lambda: random.randint(1, 5),\n    })\n    return env\n"
  },
  {
    "path": "code/chapter_17_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nREST_FRAMEWORK = {\n    'DEFAULT_PERMISSION_CLASSES': (\n        'rest_framework.permissions.IsAdminUser',\n    ),\n}\n"
  },
  {
    "path": "code/chapter_17_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/models.py\nimport uuid as uuid_lib\n\nfrom django.db import models\nfrom django.urls import reverse\n\nclass Flavor(models.Model):\n    title = models.CharField(max_length=255)\n    slug = models.SlugField(unique=True)  # Used to find the web URL\n    uuid = models.UUIDField( # Used by the API to look up the record\n        db_index=True,\n        default=uuid_lib.uuid4,\n        editable=False)\n    scoops_remaining = models.IntegerField(default=0)\n\n    def get_absolute_url(self):\n        return reverse('flavors:detail', kwargs={'slug': self.slug})\n"
  },
  {
    "path": "code/chapter_17_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/api/serializers.py\nfrom rest_framework import serializers\n\nfrom ..models import Flavor\n\nclass FlavorSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Flavor\n        fields = ['title', 'slug', 'uuid', 'scoops_remaining']\n"
  },
  {
    "path": "code/chapter_17_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/api/views.py\nfrom rest_framework.generics import (\n  ListCreateAPIView,\n  RetrieveUpdateDestroyAPIView\n)\nfrom rest_framework.permissions import IsAuthenticated\n\nfrom ..models import Flavor\nfrom .serializers import FlavorSerializer\n\nclass FlavorListCreateAPIView(ListCreateAPIView):\n    queryset = Flavor.objects.all()\n    permission_classes = (IsAuthenticated, )\n    serializer_class = FlavorSerializer\n    lookup_field = 'uuid'  # Don't use Flavor.id!\n\nclass FlavorRetrieveUpdateDestroyAPIView(RetrieveUpdateDestroyAPIView):\n    queryset = Flavor.objects.all()\n    permission_classes = (IsAuthenticated, )\n    serializer_class = FlavorSerializer\n    lookup_field = 'uuid'  # Don't use Flavor.id!\n"
  },
  {
    "path": "code/chapter_17_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/urls.py\nfrom django.urls import path\n\nfrom flavors.api import views\n\nurlpatterns = [\n    # /flavors/api/\n    path(\n        route='api/',\n        view=views.FlavorListCreateAPIView.as_view(),\n        name='flavor_rest_api'\n    ),\n    # /flavors/api/:uuid/\n    path(\n        route='api/<uuid:uuid>/',\n        view=views.FlavorRetrieveUpdateDestroyAPIView.as_view(),\n        name='flavor_rest_api'\n    )\n]\n"
  },
  {
    "path": "code/chapter_17_example_06.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nflavors/api/\nflavors/api/:uuid/\n"
  },
  {
    "path": "code/chapter_17_example_07.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nflavors/\n├── api/\n│   ├── __init__.py\n│   ├── authentication.py\n│   ├── parsers.py\n│   ├── permissions.py\n│   ├── renderers.py\n│   ├── serializers.py\n│   ├── validators.py\n│   ├── views.py\n│   ├── viewsets.py\n"
  },
  {
    "path": "code/chapter_17_example_08.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n  flavors/\n  ├── api/\n  │   ├── __init__.py\n  │   ├── ... other modules here\n  │   ├── views\n  │   │   ├── __init__.py\n  │   │   ├── flavor.py\n  │   │   ├── ingredient.py\n"
  },
  {
    "path": "code/chapter_17_example_09.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\napi/flavors/ # GET, POST\napi/flavors/:uuid/ # GET, PUT, DELETE\napi/users/ # GET, POST\napi/users/:uuid/ # GET, PUT, DELETE\n"
  },
  {
    "path": "code/chapter_17_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/api_urls.py\n\"\"\"Called from the project root's urls.py URLConf thus:\n        path('api/', include('core.api_urls', namespace='api')),\n\"\"\"\nfrom django.urls import path\n\nfrom flavors.api import views as flavor_views\nfrom users.api import views as user_views\n\nurlpatterns = [\n    # {% url 'api:flavors' %}\n    path(\n        route='flavors/',\n        view=flavor_views.FlavorCreateReadView.as_view(),\n        name='flavors'\n    ),\n    # {% url 'api:flavors' flavor.uuid %}\n    path(\n        route='flavors/<uuid:uuid>/',\n        view=flavor_views.FlavorReadUpdateDeleteView.as_view(),\n        name='flavors'\n    ),\n    # {% url 'api:users' %}\n    path(\n        route='users/',\n        view=user_views.UserCreateReadView.as_view(),\n        name='users'\n    ),\n    # {% url 'api:users' user.uuid %}\n    path(\n        route='users/<uuid:uuid>/',\n        view=user_views.UserReadUpdateDeleteView.as_view(),\n        name='users'\n    ),\n]\n\n"
  },
  {
    "path": "code/chapter_17_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# sundaes/api/views.py\nfrom django.shortcuts import get_object_or_404\n\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\n\nfrom ..models import Sundae, Syrup\nfrom .serializers import SundaeSerializer, SyrupSerializer\n\nclass PourSyrupOnSundaeView(APIView):\n    \"\"\"View dedicated to adding syrup to sundaes\"\"\"\n\n    def post(self, request, *args, **kwargs):\n        # Process pouring of syrup here,\n        # Limit each type of syrup to just one pour\n        # Max pours is 3 per sundae\n        sundae = get_object_or_404(Sundae, uuid=request.data['uuid'])\n        try:\n            sundae.add_syrup(request.data['syrup'])\n        except Sundae.TooManySyrups:\n            msg = \"Sundae already maxed out for syrups\"\n            return Response({'message': msg}, status_code=400)\n        except Syrup.DoesNotExist\n            msg = \"{}  does not exist\".format(request.data['syrup'])\n            return Response({'message': msg}, status_code=404)\n        return Response(SundaeSerializer(sundae).data)\n\n    def get(self, request, *args, **kwargs)\n        # Get list of syrups already poured onto the sundae\n        sundae = get_object_or_404(Sundae, uuid=request.data['uuid'])\n        syrups = [SyrupSerializer(x).data for x in sundae.syrup_set.all()]\n        return Response(syrups)\n"
  },
  {
    "path": "code/chapter_17_example_12.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n/sundae/  # GET, POST\n/sundae/:uuid/  # PUT, DELETE\n/sundae/:uuid/syrup/  # GET, POST\n/syrup/  # GET, POST\n/syrup/:uuid/  # PUT, DELETE\n"
  },
  {
    "path": "code/chapter_17_example_13.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n/api/cones/  # GET, POST\n/api/cones/:uuid/  # PUT, DELETE\n/api/scoops/  # GET, POST\n/api/scoops/:uuid/  # PUT, DELETE\n"
  },
  {
    "path": "code/chapter_17_example_14.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n/api/cones/  # GET, POST\n/api/cones/:uuid/  # PUT, DELETE\n/api/cones/:uuid/scoops/  # GET, POST\n/api/cones/:uuid/scoops/:uuid/  # PUT, DELETE\n/api/scoops/  # GET, POST\n/api/scoops/:uuid/  # PUT, DELETE\n"
  },
  {
    "path": "code/chapter_17_example_15.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/apiv1_shutdown.py\nfrom django.http import HttpResponseGone\n\napiv1_gone_msg = \"\"\"APIv1 was removed on April 2, 2017. Please switch to APIv2:\n<ul>\n    <li>\n        <a href=\"https://www.example.com/api/v3/\">APIv3 Endpoint</a>\n    </li>\n    <li>\n        <a href=\"https://example.com/apiv3_docs/\">APIv3 Documentation</a>\n    </li>\n    <li>\n        <a href=\"http://example.com/apiv1_shutdown/\">APIv1 shut down notice</a>\n    </li>\n</ul>\n\"\"\"\n\ndef apiv1_gone(request):\n    return HttpResponseGone(apiv1_gone_msg)\n"
  },
  {
    "path": "code/chapter_17_example_16.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass FlavorApiView(LoginRequiredMixin,View):\n    def post(self, request, *args, **kwargs):\n        # logic goes here\n        return JsonResponse({})\n\n    def get(self, request, *args, **kwargs):\n        # logic goes here\n        return JsonResponse({})\n\n    def put(self, request, *args, **kwargs):\n        # logic goes here\n        return JsonResponse({})\n\n    def delete(self, request, *args, **kwargs):\n        # logic goes here\n        return JsonResponse({})\n"
  },
  {
    "path": "code/chapter_18_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nconfig/\n├── schema.py # imports forms & models from flavors app\n├── settings/\n├── urls.py\nflavors/\n├── __init__.py\n├── app.py\n├── forms.py\n├── models.py\n"
  },
  {
    "path": "code/chapter_18_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nconfig/\n├── schema.py # imports queries/mutations from flavors app\n├── settings/\n├── urls.py\nflavors/\n├── __init__.py\n├── app.py\n├── api/\n│   ├── queries.py  # imports models\n│   ├── mutations.py  # imports forms and models\n├── forms.py\n├── models.py\n"
  },
  {
    "path": "code/chapter_19_example_01.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n{{ page_data|json_script:\"page-data\" }}\n<script>\nvar data = JSON.parse(document.getElementById('page').textContent);\ninjectNameIntoDiv('scoopName', data.scoop.name);\n</script>\n"
  },
  {
    "path": "code/chapter_21_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.db import models\n\nclass IceCreamBar(models.Model):\n    name = models.CharField(max_length=100)\n    shell = models.CharField(max_length=100)\n    filling = models.CharField(max_length=100)\n    has_stick = models.BooleanField(default=True)\n\n    def __str__(self):\n        return self.name\n"
  },
  {
    "path": "code/chapter_21_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> IceCreamBar.objects.all()\n[<IceCreamBar: Vanilla Crisp>, <IceCreamBar: Mint Cookie Crunch>,\n<IceCreamBar: Strawberry Pie>]\n"
  },
  {
    "path": "code/chapter_21_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib import admin\n\nfrom .models import IceCreamBar\n\n@admin.register(IceCreamBar)\nclass IceCreamBarModelAdmin(admin.ModelAdmin):\n    list_display = ('name', 'shell', 'filling')\n"
  },
  {
    "path": "code/chapter_21_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n  # icecreambars/admin.py\n  from django.contrib import admin\n  from django.urls import reverse, NoReverseMatch\n  from django.utils.html import format_html\n\n  from .models import IceCreamBar\n\n  @admin.register(IceCreamBar)\n  class IceCreamBarModelAdmin(admin.ModelAdmin):\n      list_display = ('name', 'shell', 'filling')\n      readonly_fields = ('show_url',)\n\n      def show_url(self, instance):\n          url = reverse('icecreambars:ice_cream_bar_detail', kwargs={'pk': instance.pk})\n          response = format_html(\"\"\"<a href=\"{0}\">{0}</a>\"\"\", url)\n          return response\n\n      show_url.short_description = 'Ice Cream Bar URL'\n\n"
  },
  {
    "path": "code/chapter_22_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Stock user model definition\n>>> from django.contrib.auth import get_user_model\n>>> get_user_model()\n<class django.contrib.auth.models.User>\n\n# When the project has a custom user model definition\n>>> from django.contrib.auth import get_user_model\n>>> get_user_model()\n<class profiles.models.UserProfile>\n"
  },
  {
    "path": "code/chapter_22_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.conf import settings\nfrom django.db import models\n\nclass IceCreamStore(models.Model):\n\n    owner = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL)\n    title = models.CharField(max_length=255)\n"
  },
  {
    "path": "code/chapter_22_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# DON'T DO THIS!\nfrom django.contrib.auth import get_user_model\nfrom django.db import models\n\nclass IceCreamStore(models.Model):\n\n    # This following line tends to create import loops.\n    owner = models.OneToOneField(get_user_model(), on_delete=models.SET_NULL)\n    title = models.CharField(max_length=255)\n"
  },
  {
    "path": "code/chapter_22_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# profiles/models.py\nfrom django.contrib.auth.models import AbstractUser\nfrom django.db import models\n\nclass KarmaUser(AbstractUser):\n    karma = models.PositiveIntegerField(verbose_name='karma',\n                                            default=0,\n                                            blank=True)\n"
  },
  {
    "path": "code/chapter_22_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nAUTH_USER_MODEL = 'profiles.KarmaUser'\n"
  },
  {
    "path": "code/chapter_22_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# profiles/models.py\n\nfrom django.conf import settings\nfrom django.db import models\n\nfrom flavors.models import Flavor\n\nclass EaterProfile(models.Model):\n\n    # Default user profile\n    # If you do this you need to either have a post_save signal or\n    #     redirect to a profile_edit view on initial login.\n    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL)\n    favorite_ice_cream = models.ForeignKey(Flavor, null=True, blank=True)\n\nclass ScooperProfile(models.Model):\n\n    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL)\n    scoops_scooped = models.IntegerField(default=0)\n\nclass InventorProfile(models.Model):\n\n    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL)\n    flavors_invented = models.ManyToManyField(Flavor, null=True, blank=True)\n"
  },
  {
    "path": "code/chapter_22_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass User(AbstractUser):\n    class Types(models.TextChoices):\n        EATER = \"EATER\", \"Eater\"\n        SCOOPER = \"SCOOPER\", \"Scooper\"\n        INVENTOR = \"INVENTOR\", \"Inventor\"\n\n    # What type of user are we?\n    type = models.CharField(\n        _(\"Type\"), max_length=50, choices=Types.choices, default=Types.EATER\n    )\n"
  },
  {
    "path": "code/chapter_22_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass User(AbstractUser):\n    class Types(models.TextChoices):\n        EATER = \"EATER\", \"Eater\"\n        SCOOPER = \"SCOOPER\", \"Scooper\"\n        INVENTOR = \"INVENTOR\", \"Inventor\"\n\n    # Ensures that creating new users through proxy models works\n    base_type = Types.EATER\n\n    # What type of user are we?\n    type = models.CharField(\n        _(\"Type\"), max_length=50,\n        choices=Types.choices,\n        default=Types.EATER\n    )\n\n    # ...\n\n    def save(self, *args, **kwargs):\n        # If a new user, set the user's type based off the\n        #   base_type property\n        if not self.pk:\n            self.type = self.base_type\n        return super().save(*args, **kwargs)           \n"
  },
  {
    "path": "code/chapter_22_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass InventorManager(BaseUserManager):\n    def get_queryset(self, *args, **kwargs):\n        results = super().get_queryset(*args, **kwargs)\n        return results.filter(type=User.Types.INVENTOR)\n\nclass Inventor(User):\n    # This sets the user type to INVENTOR during record creation\n    base_type = User.Types.INVENTOR\n\n    # Ensures queries on the Inventor model return only Inventors\n    objects = InventorManager()\n\n    # Setting proxy to \"True\" means a table WILL NOT be created\n    #    for this record\n    class Meta:\n        proxy = True\n\n    # Only inventors get to invent new flavors!\n    def invent(self):\n        # Magical custom logic goes Here\n        return \"Delicious!\"\n"
  },
  {
    "path": "code/chapter_22_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from users.models import User, Inventor\n>>> User.objects.count() # Over 300 million users!\n323482357\n>>> Inventor.objects.count() # But only 3 inventors\n3\n>>> # Calling someone as both a User and an Inventor\n>>> user = User.objects.get(username='uma')\n>>> user\n<User: uma>\n>>> inventor = Inventor.objects.get(username='uma')\n>>> inventor\n<Inventor: uma>\n>>> # Calling a method that's only for inventors\n>>> user.invent()\nAttributeError\n>>> inventor.invent()\n'Delicious'\n"
  },
  {
    "path": "code/chapter_22_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> User.objects.filter(type=User.Types.INVENTOR)\n>>> Inventor.objects.filter()  # Our preference\n"
  },
  {
    "path": "code/chapter_22_example_12.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nclass Inventor(User):\n    # ...\n    objects = InventorManager()\n\n    class Meta:\n        proxy = True\n\n    @property\n    def extra(self):\n        return self.inventorprofile\n\nclass Scooper(User):\n    # ...\n    objects = ScooperManager()\n\n    class Meta:\n        proxy = True\n\n    @property\n    def extra(self):\n        return self.scooperprofile     \n\nclass Eater(User):\n    # ...\n    objects = EaterManager()\n\n    class Meta:\n        proxy = True\n\n    @property\n    def extra(self):\n        return self.eaterprofile            \n"
  },
  {
    "path": "code/chapter_23_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nDjango==1.11\ncoverage==4.3.4\ndjango-extensions==1.7.6\ndjango-braces==1.11\n"
  },
  {
    "path": "code/chapter_23_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n\n-e git+https://github.com/erly-adptr/py-junk.git#egg=py-jnk\n"
  },
  {
    "path": "code/chapter_23_example_03.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# DON'T DO THIS!\n# requirements for django-blarg\n\nDjango==3.0\nrequests==2.11.0\n"
  },
  {
    "path": "code/chapter_23_example_04.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# requirements.txt for the mythical web site 'icecreamratings.com'\nDjango==3.1\nrequests==2.13.0\ndjango−blarg==1.0\n\n# Note that unlike the django−blarg library , we explicitly pin\n# the requirements so we have total control over the environment\n"
  },
  {
    "path": "code/chapter_23_example_05.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# requirements for django-blarg\n\nDjango>=3.1,<3.0\nrequests>=2.13.0,<=3.0.0\n"
  },
  {
    "path": "code/chapter_23_example_06.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# Only if you haven't installed cookiecutter yet\n\\$ pip install cookiecutter\n\n# Creating a Django Package from scratch\n\\$ cookiecutter https://github.com/pydanny/cookiecutter-djangopackage.git\n\n# Creating a Python Package from scratch\n\\$ cookiecutter https://github.com//ionelmc/cookiecutter-pylibrary.git\n"
  },
  {
    "path": "code/chapter_23_example_07.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npip install twine\npython setup.py sdist\ntwine upload dist/*\n"
  },
  {
    "path": "code/chapter_23_example_08.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npip install wheel\n"
  },
  {
    "path": "code/chapter_23_example_09.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npython setup.py bdist_wheel\ntwine upload dist/*\n"
  },
  {
    "path": "code/chapter_23_example_10.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# setup.cfg\n[wheel]\nuniversal = 1\n"
  },
  {
    "path": "code/chapter_23_example_11.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ngit tag -a v1.4 -m \"my version 1.4\"\ngit push origin v1.4\n"
  },
  {
    "path": "code/chapter_24_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npopsicles/\n    __init__.py\n    admin.py\n    forms.py\n    models.py\n    tests/\n        __init__.py\n        test_forms.py\n        test_models.py\n        test_views.py\n    views.py\n"
  },
  {
    "path": "code/chapter_24_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/tests/test_api.py\nimport json\n\nfrom django.test import TestCase\nfrom django.urls import reverse\n\nfrom flavors.models import Flavor\n\nclass FlavorAPITests(TestCase):\n\n    def setUp(self):\n        Flavor.objects.get_or_create(title='A Title', slug='a-slug')\n\n    def test_list(self):\n        url = reverse('flavors:flavor_object_api')\n        response = self.client.get(url)\n        self.assertEquals(response.status_code, 200)\n        data = json.loads(response.content)\n        self.assertEquals(len(data), 1)\n"
  },
  {
    "path": "code/chapter_24_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# flavors/tests/test_api.py\nimport json\n\nfrom django.test import TestCase\nfrom django.urls import reverse\n\nfrom flavors.models import Flavor\n\nclass DjangoRestFrameworkTests(TestCase):\n\n    def setUp(self):\n        Flavor.objects.get_or_create(title='title1', slug='slug1')\n        Flavor.objects.get_or_create(title='title2', slug='slug2')\n\n        self.create_read_url = reverse('flavors:flavor_rest_api')\n        self.read_update_delete_url = \\\n            reverse('flavors:flavor_rest_api', kwargs={'slug': 'slug1'})\n\n    def test_list(self):\n        response = self.client.get(self.create_read_url)\n\n        # Are both titles in the content?\n        self.assertContains(response, 'title1')\n        self.assertContains(response, 'title2')\n\n    def test_detail(self):\n        response = self.client.get(self.read_update_delete_url)\n        data = json.loads(response.content)\n        content = {'id': 1, 'title': 'title1', 'slug': 'slug1',\n                                            'scoops_remaining': 0}\n        self.assertEquals(data, content)\n\n    def test_create(self):\n        post = {'title': 'title3', 'slug': 'slug3'}\n        response = self.client.post(self.create_read_url, post)\n        data = json.loads(response.content)\n        self.assertEquals(response.status_code, 201)\n        content = {'id': 3, 'title': 'title3', 'slug': 'slug3',\n                                            'scoops_remaining': 0}\n        self.assertEquals(data, content)\n        self.assertEquals(Flavor.objects.count(), 3)\n\n    def test_delete(self):\n        response = self.client.delete(self.read_update_delete_url)\n        self.assertEquals(response.status_code, 204)\n        self.assertEquals(Flavor.objects.count(), 1)\n"
  },
  {
    "path": "code/chapter_24_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.contrib.auth.models import AnonymousUser\nfrom django.contrib.sessions.middleware import SessionMiddleware\nfrom django.test import TestCase, RequestFactory\n\nfrom .views import cheese_flavors\n\ndef add_middleware_to_request(request, middleware_class):\n    middleware = middleware_class()\n    middleware.process_request(request)\n    return request\n\ndef add_middleware_to_response(request, middleware_class):\n    middleware = middleware_class()\n    middleware.process_response(request)\n    return request\n\nclass SavoryIceCreamTest(TestCase):\n    def setUp(self):\n        # Every test needs access to the request factory.\n        self.factory = RequestFactory()\n\n    def test_cheese_flavors(self):\n        request = self.factory.get('/cheesy/broccoli/')\n        request.user = AnonymousUser()\n\n        # Annotate the request object with a session\n        request = add_middleware_to_request(request, SessionMiddleware)\n        request.session.save()\n\n        # process and test the request\n        response = cheese_flavors(request)\n        self.assertContains(response, 'bleah!')\n"
  },
  {
    "path": "code/chapter_24_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom unittest import mock, TestCase\n\nimport icecreamapi\n\nfrom flavors.exceptions import CantListFlavors\nfrom flavors.utils import list_flavors_sorted\n\nclass TestIceCreamSorting(TestCase):\n\n    # Set up monkeypatch of icecreamapi.get_flavors()\n    @mock.patch.object(icecreamapi, 'get_flavors')\n    def test_flavor_sort(self, get_flavors):\n        # Instructs icecreamapi.get_flavors() to return an unordered list.\n        get_flavors.return_value = ['chocolate', 'vanilla', 'strawberry', ]\n\n        # list_flavors_sorted() calls the icecreamapi.get_flavors()\n        #   function. Since we've monkeypatched the function,  it will always\n        #   return ['chocolate', 'strawberry', 'vanilla', ]. Which the.\n        #   list_flavors_sorted() will sort alphabetically\n        flavors = list_flavors_sorted()\n\n        self.assertEqual(\n            flavors,\n            ['chocolate', 'strawberry', 'vanilla', ]\n\n        )\n"
  },
  {
    "path": "code/chapter_24_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n    @mock.patch.object(icecreamapi, 'get_flavors')\n    def test_flavor_sort_failure(self, get_flavors):\n        # Instructs icecreamapi.get_flavors() to throw a FlavorError.\n        get_flavors.side_effect = icecreamapi.FlavorError()\n\n        # list_flavors_sorted() catches the icecreamapi.FlavorError()\n        #   and passes on a CantListFlavors exception.\n        with self.assertRaises(CantListFlavors):\n            list_flavors_sorted()\n"
  },
  {
    "path": "code/chapter_24_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n    @mock.patch.object(requests, 'get')\n    def test_request_failure(self, get):\n        \"\"\"Test if the target site is inaccessible.\"\"\"\n        get.side_effect = requests.exception.ConnectionError()\n\n        with self.assertRaises(CantListFlavors):\n            list_flavors_sorted()\n\n    @mock.patch.object(requests, 'get')\n    def test_request_failure_ssl(self, get):\n        \"\"\"Test if we can handle SSL problems elegantly.\"\"\"\n        get.side_effect = requests.exception.SSLError()\n\n        with self.assertRaises(CantListFlavors):\n            list_flavors_sorted()\n"
  },
  {
    "path": "code/chapter_24_example_08.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ coverage run manage.py test --settings=twoscoops.settings.test\n"
  },
  {
    "path": "code/chapter_24_example_09.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nCreating test database for alias \"default\"...\n..\n-----------------------------------------------\nRan 2 tests in 0.008s\n\nOK\n\nDestroying test database for alias \"default\"...\n"
  },
  {
    "path": "code/chapter_24_example_10.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ coverage html --omit=\"admin.py\"\n"
  },
  {
    "path": "code/chapter_24_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# test_models.py\nfrom pytest import raises\n\nfrom cones.models import Cone\n\ndef test_good_choice():\n    assert Cone.objects.filter(type='sugar').count() == 1\n\ndef test_bad_cone_choice():\n    with raises(Cone.DoesNotExist):\n        Cone.objects.get(type='spaghetti')\n"
  },
  {
    "path": "code/chapter_25_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n# H1 Header\n\n**emphasis (bold/strong)**\n\n*italics*\n\n_underline_\n\nlink: [Two Scoops Press](https://twoscoopspress.com)\n\nNote: The secret to links in Markdown is think of it like a function call. The link in the paranthesis is the value being called.\n\n\n## Section Header\n\n#. An enumerated list item\n#. Second item\n\n- First bullet\n\n- Second bullet\n\n  - Indented Bullet\n\n  - Note carriage return and indents\n\nLiteral code block:\n\n``` python\ndef like():\n    print(\"I like Ice Cream\")\n\nfor i in range(10):\n    like()\n```\n\nJavaScript colored code block:\n\n``` js\nconsole.log(\"Don't use alert()\");\n```\n"
  },
  {
    "path": "code/chapter_25_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n\\$ # To convert a ReStructuredText document to GitHub-Flavored Markdown\n\\$ pandoc -t gfm README.rst -o README.md\n\\$ # To convert a Markdown document to ReStructuredText\n\\$ pandoc -f gfm README.md -o README.rst\n"
  },
  {
    "path": "code/chapter_28_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nSESSION_COOKIE_SECURE = True\nCSRF_COOKIE_SECURE = True\n"
  },
  {
    "path": "code/chapter_28_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nStrict-Transport-Security: max-age=31536000; includeSubDomains\n"
  },
  {
    "path": "code/chapter_28_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django import forms\n\nclass SpecialForm(forms.Form):\n    my_secret = forms.CharField(\n            widget=forms.TextInput(attrs={'autocomplete': 'off'}))\n"
  },
  {
    "path": "code/chapter_28_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django import forms\n\nclass SecretInPublicForm(forms.Form):\n\n    my_secret = forms.CharField(widget=forms.PasswordInput())\n"
  },
  {
    "path": "code/chapter_28_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/models.py\nfrom django.conf import settings\nfrom django.db import models\n\nclass Store(models.Model):\n    title = models.CharField(max_length=255)\n    slug = models.SlugField()\n    owner = models.ForeignKey(settings.AUTH_USER_MODEL)\n    # Assume 10 more fields that cover address and contact info.\n"
  },
  {
    "path": "code/chapter_28_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# DON'T DO THIS!\nfrom django import forms\n\nfrom .models import Store\n\nclass StoreForm(forms.ModelForm):\n\n    class Meta:\n        model = Store\n        # DON'T DO THIS: Implicit definition of fields.\n        #                Too easy to make mistakes!\n        excludes = (\"pk\", \"slug\", \"modified\", \"created\", \"owner\")\n"
  },
  {
    "path": "code/chapter_28_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django import forms\n\nfrom .models import Store\n\nclass StoreForm(forms.ModelForm):\n\n    class Meta:\n        model = Store\n        # Explicitly specifying the fields we want\n        fields = (\n            \"title\", \"address_1\", \"address_2\", \"email\",\n            \"usstate\", \"postal_code\", \"city\",\n        )\n"
  },
  {
    "path": "code/chapter_28_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/models.py\nfrom django.conf import settings\nfrom django.db import models\n\nclass Store(models.Model):\n    title = models.CharField(max_length=255)\n    slug = models.SlugField()\n    owner = models.ForeignKey(settings.AUTH_USER_MODEL)\n    co_owners = models.ManyToManyField(settings.AUTH_USER_MODEL)\n    # Assume 10 more fields that cover address and contact info.\n"
  },
  {
    "path": "code/chapter_28_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nimport uuid\nfrom django.db import models\n\nclass IceCreamPayment(models.Model):\n    uuid = models.UUIDField(\n        unique=True,\n        default=uuid.uuid4,\n        editable=False)\n\n    def __str__(self):\n        return str(self.pk)\n"
  },
  {
    "path": "code/chapter_28_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from payments import IceCreamPayment\n>>> payment = IceCreamPayment()\n>>> IceCreamPayment.objects.get(id=payment.id)\n<IceCreamPayment: 1>\n>>> payment.uuid\nUUID('0b0fb68e-5b06-44af-845a-01b6df5e0967')\n>>> IceCreamPayment.objects.get(uuid=payment.uuid)\n<IceCreamPayment: 1>\n"
  },
  {
    "path": "code/chapter_28_example_11.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<!-- DON'T DO THIS - loading static assets without SRI -->\n<link rel=\"stylesheet\"\n  href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\">\n\n<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\"></script>\n<script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js\"></script>   \n"
  },
  {
    "path": "code/chapter_28_example_12.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<!-- Loading Static Assets with SRI -->\n<link rel=\"stylesheet\"\n  href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\"\n  integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\"\n  crossorigin=\"anonymous\">\n<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"\n  integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\"\n  crossorigin=\"anonymous\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\" \n  integrity=\"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1\" \n  crossorigin=\"anonymous\"></script>\n<script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js\" \n  integrity=\"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM\"   \n  crossorigin=\"anonymous\"></script>  \n"
  },
  {
    "path": "code/chapter_29_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Taken directly from core Django code.\n# Used here to illustrate an example only, so don't\n# copy this into your project.\nlogger.error('Internal Server Error: %s', request.path,\n    exc_info=exc_info,\n    extra={\n        'status_code': 500,\n        'request': request\n    }\n)\n"
  },
  {
    "path": "code/chapter_29_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Taken directly from core Django code.\n# Used here to illustrate an example only, so don't\n# copy this into your project.\nlogger.warning('Forbidden (%s): %s',\n               REASON_NO_CSRF_COOKIE, request.path,\n    extra={\n        'status_code': 403,\n        'request': request,\n    }\n)\n"
  },
  {
    "path": "code/chapter_29_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.views.generic import TemplateView\n\nfrom .helpers import pint_counter\n\nclass PintView(TemplateView):\n\n    def get_context_data(self, *args, **kwargs):\n        context = super().get_context_data(**kwargs)\n        pints_remaining = pint_counter()\n        print(f'Only {pints_remaining} pints of ice cream left.')\n        return context\n\n"
  },
  {
    "path": "code/chapter_29_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nimport logging\n\nfrom django.views.generic import TemplateView\n\nfrom .helpers import pint_counter\n\nlogger = logging.getLogger(__name__)\n\nclass PintView(TemplateView):\n\n    def get_context_data(self, *args, **kwargs):\n        context = super().get_context_data(**kwargs)\n        pints_remaining = pint_counter()\n        logger.debug('Only %d pints of ice cream left.' % pints_remaining)\n        return context\n"
  },
  {
    "path": "code/chapter_29_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nimport logging\nimport requests\n\nlogger = logging.getLogger(__name__)\n\ndef get_additional_data():\n    try:\n        r = requests.get('http://example.com/something-optional/')\n    except requests.HTTPError as e:\n        logger.exception(e)\n        logger.debug('Could not get additional data', exc_info=True)\n        return None\n    return r\n"
  },
  {
    "path": "code/chapter_29_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# You can place this snippet at the top\n# of models.py, views.py, or any other\n# file where you need to log.\nimport logging\n\nlogger = logging.getLogger(__name__)\n"
  },
  {
    "path": "code/chapter_30_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# events/managers.py\nfrom django.db import models\n\nclass EventManager(models.Manager):\n\n    def create_event(self, title, start, end, creator):\n        event = self.model(title=title,\n                            start=start,\n                            end=end,\n                            creator=creator)\n        event.save()\n        event.notify_admins()\n        return event\n\n"
  },
  {
    "path": "code/chapter_30_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# events/models.py\nfrom textwrap import dedent\n\nfrom django.conf import settings\nfrom django.core.mail import mail_admins\nfrom django.db import models\n\nfrom model_utils.models import TimeStampedModel\n\nfrom .managers import EventManager\n\nclass Event(TimeStampedModel):\n\n    class Status(models.IntegerChoices):\n        STATUS_UNREVIEWED = 0, \"Unreviewed\"\n        STATUS_REVIEWED = 1, \"Reviewed\"\n\n\n    title = models.CharField(max_length=100)\n    start = models.DateTimeField()\n    end = models.DateTimeField()\n    status = models.IntegerField(choices=Status.choices,\n                                    default=Status.STATUS_UNREVIEWED)\n    creator = models.ForeignKey(settings.AUTH_USER_MODEL,\n                                on_delete=models.CASCADE)\n\n    objects = EventManager()\n\n    def notify_admins(self):\n        # create the subject and message\n        subject = \"{user} submitted a new event!\".format(\n                        user=self.creator.get_full_name())\n        message = dedentf\"\"\"TITLE: {self.title}\n                  START: {self.start}\n                  END: {self.end}\"\"\")\n\n        # Send to the admins!\n        mail_admins(subject=subject,\n            message=message,\n            fail_silently=False)\n"
  },
  {
    "path": "code/chapter_30_example_03.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n>>> from django.contrib.auth import get_user_model\n>>> from django.utils import timezone\n>>> from events.models import Event\n>>> user = get_user_model().objects.get(username=\"audreyr\")\n>>> now = timezone.now()\n>>> event = Event.objects.create_event(\n...     title=\"International Ice Cream Tasting Competition\",\n...     start=now,\n...     end=now,\n...     user=user\n...     )\n"
  },
  {
    "path": "code/chapter_31_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ncore/\n    __init__.py\n    managers.py  # contains the custom model manager(s)\n    models.py\n    views.py  # Contains the custom view mixin(s)\n"
  },
  {
    "path": "code/chapter_31_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom core.managers import PublishedManager\nfrom core.views import IceCreamMixin\n"
  },
  {
    "path": "code/chapter_31_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> from django.utils.text import slugify\n>>> slugify('straße') # German\n'strae'\n"
  },
  {
    "path": "code/chapter_31_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n>>> slugify('straße', allow_unicode=True) # Again with German\n'straße'\n"
  },
  {
    "path": "code/chapter_31_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/utils.py\nfrom django.core.exceptions import ObjectDoesNotExist\n\nclass BorkedObject:\n    loaded = False\n\ndef generic_load_tool(model, pk):\n    try:\n        instance = model.objects.get(pk=pk)\n    except ObjectDoesNotExist:\n        return BorkedObject()\n    instance.loaded = True\n    return instance\n"
  },
  {
    "path": "code/chapter_31_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/utils.py\nfrom django.core.exceptions import MultipleObjectsReturned\nfrom django.core.exceptions import ObjectDoesNotExist\nfrom django.core.exceptions import PermissionDenied\n\ndef get_object_or_403(model, **kwargs):\n    try:\n        return model.objects.get(**kwargs)\n    except ObjectDoesNotExist:\n        raise PermissionDenied\n    except MultipleObjectsReturned:\n        raise PermissionDenied\n"
  },
  {
    "path": "code/chapter_31_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/calc.py\n\ndef finance_data_adjudication(store, sales, issues):\n\n    if store.something_not_right:\n        msg = 'Something is not right. Please contact the support team.'\n        raise PermissionDenied(msg)\n\n    # Continue on to perform other logic.\n"
  },
  {
    "path": "code/chapter_31_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# urls.py\n\n# This demonstrates the use of a custom permission denied view. The default\n# view is django.views.defaults.permission_denied\nhandler403 = 'core.views.permission_denied_view'\n"
  },
  {
    "path": "code/chapter_31_example_09.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# serializer_example.py\nfrom django.core.serializers import get_serializer\n\nfrom favorites.models import Favorite\n\n# Get and instantiate the serializer class\n# The 'json' can be replaced with 'python' or 'xml'.\n# If you have pyyaml installed, you can replace it with\n#   'pyyaml'\nJSONSerializer = get_serializer('json')\nserializer = JSONSerializer()\n\nfavs = Favorite.objects.filter()[:5]\n\n# Serialize model data\nserialized_data = serializer.serialize(favs)\n\n# save the serialized data for use in the next example\nwith open('data.json', 'w') as f:\n    f.write(serialized_data)\n\n"
  },
  {
    "path": "code/chapter_31_example_10.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# deserializer_example.py\nfrom django.core.serializers import get_serializer\n\nfrom favorites.models import Favorite\n\n# Get and instantiate the serializer class\n# The 'json' can be replaced with 'python' or 'xml'.\n# If you have pyyaml installed, you can replace it with\n#   'pyyaml'\nJSONSerializer = get_serializer('json')\nserializer = JSONSerializer()\n\n# open the serialized data file\nwith open('data.txt') as f:\n    serialized_data = f.read()\n\n# deserialize model data into a generator object\n#   we'll call 'python data'\npython_data = serializer.deserialize(serialized_data)\n\n# iterate through the python_data\nfor element in python_data:\n    # Prints 'django.core.serializers.base.DeserializedObject'\n    print(type(element))\n\n    # Elements have an 'object' that are literally instantiated\n    #   model instances (in this case, favorites.models.Favorite)\n    print(\n        element.object.pk,\n        element.object.created\n    )\n\n"
  },
  {
    "path": "code/chapter_31_example_11.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# json_encoding_example.py\nimport json\n\nfrom django.core.serializers.json import DjangoJSONEncoder\nfrom django.utils import timezone\n\ndata = {'date': timezone.now()}\n\n# If you don't add the DjangoJSONEncoder class then\n# the json library will throw a TypeError.\njson_data = json.dumps(data, cls=DjangoJSONEncoder)\n\nprint(json_data)\n"
  },
  {
    "path": "code/chapter_35_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\ntwoscoopspress\\$ python discounts/manage.py runserver 8001\nStarting development server at http://127.0.0.1:8001/\nQuit the server with CONTROL-C.\n\nInternal Server Error: /\nTraceback (most recent call last):\n  File \"/.envs/oc/lib/python.7/site-packages/django/core/handlers/base.py\",\n        line 132, in get_response response = wrapped_callback(request,\n        *callback_args, **callback_kwargs)\n  File \"/.envs/oc/lib/python.7/site-packages/django/utils/decorators.py\",\n        line 145, in inner\n    return func(*args, **kwargs)\nTypeError: __init__() takes exactly 1 argument (2 given)\n"
  },
  {
    "path": "code/chapter_35_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Forgetting the 'as_view()' method\npath('',  HomePageView, name='home'),\n"
  },
  {
    "path": "code/chapter_35_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\npath('',  HomePageView.as_view(), name='home'),\n"
  },
  {
    "path": "code/chapter_35_example_04.html",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n<form action=\"{% url 'stores:file_upload' store.pk %}\"\n        method=\"post\"\n        enctype=\"multipart/form-data\">\n"
  },
  {
    "path": "code/chapter_35_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/views.py\n\nfrom django.shortcuts import render, redirect, get_object_or_404\nfrom django.views.generic import View\n\nfrom stores.forms import UploadFileForm\nfrom stores.models import Store\n\ndef upload_file(request, pk):\n    \"\"\"Simple FBV example\"\"\"\n    store = get_object_or_404(Store, pk=pk)\n    if request.method == 'POST':\n        # Don't forget to add request.FILES!\n        form = UploadFileForm(request.POST, request.FILES)\n        if form.is_valid():\n            store.handle_uploaded_file(request.FILES['file'])\n            return redirect(store)\n    else:\n        form = UploadFileForm()\n    return render(request, 'upload.html', {'form': form, 'store': store})\n"
  },
  {
    "path": "code/chapter_35_example_06.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# stores/views.py\nfrom django.shortcuts import render, redirect, get_object_or_404\nfrom django.views.generic import View\n\nfrom stores.forms import UploadFileForm\nfrom stores.models import Store\n\nclass UploadFile(View):\n    \"\"\"Simple CBV example\"\"\"\n    def get_object(self):\n        return get_object_or_404(Store, pk=self.kwargs['pk'])\n\n    def post(self, request, *args, **kwargs):\n        store = self.get_object()\n        form = UploadFileForm(request.POST, request.FILES)\n        if form.is_valid():\n            store.handle_uploaded_file(request.FILES['file'])\n            return redirect(store)\n        return redirect('stores:file_upload', pk=pk)\n\n    def get(self, request, *args, **kwargs):\n        store = self.get_object()\n        form = UploadFileForm()\n        return render(\n            request,\n            'upload.html',\n            {'form': form, 'store': store})\n"
  },
  {
    "path": "code/chapter_35_example_07.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# core/middleware.py\nimport sys\n\nfrom django.views.debug import technical_500_response\n\nclass UserBasedExceptionMiddleware:\n    def process_exception(self, request, exception):\n        if request.user.is_superuser:\n            return technical_500_response(request, *sys.exc_info())\n"
  },
  {
    "path": "code/chapter_35_example_08.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# settings.py\nALLOWED_HOSTS = [\n    '.djangopackages.org',\n    '.djangopackages.com',\n]\n"
  },
  {
    "path": "code/chapter_39_example_01.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npython -c \"import django; print(django.get_version())\"\n\n"
  },
  {
    "path": "code/chapter_39_example_02.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n3.x, where \"x\" is the version of Django you are using\n"
  },
  {
    "path": "code/chapter_39_example_03.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n$ virtualenv testenv\n$ source testenv/bin/activate\n"
  },
  {
    "path": "code/chapter_39_example_04.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\nC:\\code\\> virtualenv testenv\nC:\\code\\> testenv\\Scripts\\activate\n"
  },
  {
    "path": "code/chapter_39_example_05.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n(testenv) \\$\n"
  },
  {
    "path": "code/chapter_39_example_06.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n(testenv) >\n"
  },
  {
    "path": "code/chapter_39_example_07.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\npython -c \"import django; print(django.get_version())\"\n"
  },
  {
    "path": "code/chapter_39_example_08.txt",
    "content": "Using This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\n********************\n\n(testenv) \\$ pip install Django==3.2\n"
  },
  {
    "path": "code/chapter_41_example_01.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.utils.translation import gettext as _\n\nprint(_('We like gelato.'))\n"
  },
  {
    "path": "code/chapter_41_example_02.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# DON'T DO THIS!\n\n# Skipping the rest of imports for the sake of brevity\nclass FlavorActionMixin:\n\n    @property\n    def action(self):\n        msg = '{0} is missing action.'.format(self.__class__)\n        raise NotImplementedError(msg)\n\n    def form_valid(self, form):\n        msg = 'Flavor {0}!'.format(self.action)\n        messages.info(self.request, msg)\n        return super().form_valid(form)\n\n# Snipping the rest of this module for the sake of brevity\n"
  },
  {
    "path": "code/chapter_41_example_03.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# DON'T DO THIS!\nfrom django.utils.translations import gettext as _\n\n# Skipping the rest of this module for the sake of brevity\n\n    def form_valid(self, form):\n\n        # This generates a useless translation object.\n        msg = _('Flavor {0}!'.format(self.action))\n        messages.info(self.request, msg)\n        return super().form_valid(form)\n\n# Skipping the rest of this module for the sake of brevity\n"
  },
  {
    "path": "code/chapter_41_example_04.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\n# Skipping the rest of imports for the sake of brevity\nfrom django.utils.translation import gettext as _\n\nclass FlavorActionMixin:\n\n    @property\n    def success_msg(self):\n        return NotImplemented\n\nclass FlavorCreateView(LoginRequiredMixin, FlavorActionMixin,\n                        CreateView):\n    model = Flavor\n\n    # Slightly longer but more meaningful dialogue\n    success_msg = _('Flavor created!')\n\n# Skipping the rest of this module for the sake of brevity\n"
  },
  {
    "path": "code/chapter_41_example_05.py",
    "content": "\"\"\"\nUsing This Code Example\n=========================\nThe code examples provided are provided by Daniel and Audrey Roy Greenfeld of\nfeldroy.com to help you reference Two Scoops of Django: Best Practices\nfor Django 3.x. Code samples follow PEP-0008, with exceptions made for the\npurposes of improving book formatting. Example code is provided \"as is\", and\nis not intended to be, and should not be considered or labeled as \"tutorial\ncode\".\n\nPermissions\n============\nIn general, you may use the code we've provided with this book in your\nprograms and documentation. You do not need to contact us for permission\nunless you're reproducing a significant portion of the code or using it in\ncommercial distributions. Examples:\n* Writing a program that uses several chunks of code from this course does\n    not require permission.\n* Selling or distributing a digital package from material taken from this\n    book does require permission.\n* Answering a question by citing this book and quoting example code does not\n    require permission.\n* Incorporating a significant amount of example code from this book into your\n    product's documentation does require permission.\nAttributions usually include the title, author, publisher and an ISBN. For\nexample, \"Two Scoops of Django: Best Practices for Django 3.x, by Daniel and\nAudrey Roy Greenfeld. Copyright 2020 Feldroy.com.\"\n\nIf you feel your use of code examples falls outside fair use of the permission\ngiven here, please contact us at hi@feldroy.com.\n\"\"\"\n\nfrom django.utils.translation import gettext as _\n\nclass FlavorActionMixin:\n\n    @property\n    def success_msg(self):\n        return NotImplemented\n\nclass FlavorCreateView(LoginRequiredMixin, FlavorActionMixin,\n                        CreateView):\n    model = Flavor\n\n    # Example combining strings\n    part_one = _('Flavor created! ')\n    part_two = _(\"Let's go try it!\")\n    success_msg = part_one + part_two\n\n# Skipping the rest of this module for the sake of brevity\n"
  }
]