March 2020
Intermediate to advanced
301 pages
7h 10m
English
Suppose you wanted to use Django instead of SQLAlchemy and Flask. How might things look? The first thing is to choose where to install it. We put it in a separate package next to our main allocation code:
├──src│├──allocation││├──__init__.py││├──adapters│││├──__init__.py...│├──djangoproject││├──alloc│││├──__init__.py│││├──apps.py│││├──migrations││││├──0001_initial.py││││└──__init__.py│││├──models.py│││└──views.py││├──django_project│││├──__init__.py│││├──settings.py│││├──urls.py│││└──wsgi.py││└──manage.py│└──setup.py└──tests├──conftest.py├──e2e│└──test_api.py├──integration│├──test_repository.py...
The code for this appendix is in the appendix_django branch on GitHub:
git clone https://github.com/cosmicpython/code.git cd code git checkout appendix_django
We used a plug-in called
pytest-django to help with test
database management.
Rewriting the first repository test was a minimal change—just rewriting some raw SQL with a call to the Django ORM/QuerySet language:
First repository test adapted (tests/integration/test_repository.py)
fromdjangoproject.allocimportmodelsasdjango_models@pytest.mark.django_dbdeftest_repository_can_save_a_batch():batch=model.Batch("batch1" ...
Read now
Unlock full access