131131< h2 id ="appendix_django "> Appendix D: Repository and Unit of Work Patterns with Django</ h2 >
132132< div class ="sectionbody ">
133133< div class ="paragraph ">
134- < p > Suppose you wanted to use Django instead of SQLAlchemy and Flask. How
134+ < p >
135+
136+ Suppose you wanted to use Django instead of SQLAlchemy and Flask. How
135137might things look? The first thing is to choose where to install it. We put it in a separate
136138package next to our main allocation code:</ p >
137139</ div >
@@ -197,7 +199,10 @@ <h2 id="appendix_django">Appendix D: Repository and Unit of Work Patterns with D
197199< div class ="sect2 ">
198200< h3 id ="_repository_pattern_with_django "> Repository Pattern with Django</ h3 >
199201< div class ="paragraph ">
200- < p > We used a plug-in called
202+ < p >
203+
204+
205+ We used a plugin called
201206< a href ="https://github.com/pytest-dev/pytest-django "> < code > pytest-django</ code > </ a > to help with test
202207database management.</ p >
203208</ div >
@@ -299,7 +304,9 @@ <h3 id="_repository_pattern_with_django">Repository Pattern with Django</h3>
299304< div class ="sect3 ">
300305< h4 id ="_custom_methods_on_django_orm_classes_to_translate_tofrom_our_domain_model "> Custom Methods on Django ORM Classes to Translate to/from Our Domain Model</ h4 >
301306< div class ="paragraph ">
302- < p > Those custom methods look something like this:</ p >
307+ < p >
308+
309+ Those custom methods look something like this:</ p >
303310</ div >
304311< div id ="django_models " class ="exampleblock ">
305312< div class ="title "> Django ORM with custom methods for domain model conversion (src/djangoproject/alloc/models.py)</ div >
@@ -372,6 +379,8 @@ <h4 id="_custom_methods_on_django_orm_classes_to_translate_tofrom_our_domain_mod
372379< td class ="content ">
373380As in < a href ="/book/chapter_02_repository.html "> [chapter_02_repository]</ a > , we use dependency inversion.
374381 The ORM (Django) depends on the model and not the other way around.
382+
383+
375384</ td >
376385</ tr >
377386</ table >
@@ -381,7 +390,9 @@ <h4 id="_custom_methods_on_django_orm_classes_to_translate_tofrom_our_domain_mod
381390< div class ="sect2 ">
382391< h3 id ="_unit_of_work_pattern_with_django "> Unit of Work Pattern with Django</ h3 >
383392< div class ="paragraph ">
384- < p > The tests don’t change too much:</ p >
393+ < p >
394+
395+ The tests don’t change too much:</ p >
385396</ div >
386397< div id ="test_uow_django " class ="exampleblock ">
387398< div class ="title "> Adapted UoW tests (tests/integration/test_uow.py)</ div >
@@ -483,15 +494,21 @@ <h3 id="_unit_of_work_pattern_with_django">Unit of Work Pattern with Django</h3>
483494instrumenting the domain model instances themselves, the
484495< code > commit()</ code > command needs to explicitly go through all the
485496objects that have been touched by every repository and manually
486- update them back to the ORM.</ p >
497+ update them back to the ORM.
498+
499+ </ p >
487500</ li >
488501</ ol >
489502</ div >
490503</ div >
491504< div class ="sect2 ">
492505< h3 id ="_api_django_views_are_adapters "> API: Django Views Are Adapters</ h3 >
493506< div class ="paragraph ">
494- < p > The Django < em > views.py</ em > file ends up being almost identical to the
507+ < p >
508+
509+
510+
511+ The Django < em > views.py</ em > file ends up being almost identical to the
495512old < em > flask_app.py</ em > , because our architecture means it’s a very
496513thin wrapper around our service layer (which didn’t change at all, by the way):</ p >
497514</ div >
@@ -537,7 +554,8 @@ <h3 id="_api_django_views_are_adapters">API: Django Views Are Adapters</h3>
537554< div class ="sect2 ">
538555< h3 id ="_why_was_this_all_so_hard "> Why Was This All So Hard?</ h3 >
539556< div class ="paragraph ">
540- < p > OK, it works, but it does feel like more effort than Flask/SQLAlchemy. Why is
557+ < p >
558+ OK, it works, but it does feel like more effort than Flask/SQLAlchemy. Why is
541559that?</ p >
542560</ div >
543561< div class ="paragraph ">
@@ -549,7 +567,8 @@ <h3 id="_why_was_this_all_so_hard">Why Was This All So Hard?</h3>
549567high).</ p >
550568</ div >
551569< div class ="paragraph ">
552- < p > Because Django is so tightly coupled to the database, you have to use helpers
570+ < p >
571+ Because Django is so tightly coupled to the database, you have to use helpers
553572like < code > pytest-django</ code > and think carefully about test databases, right from
554573the very first line of code, in a way that we didn’t have to when we started
555574out with our pure domain model.</ p >
@@ -570,7 +589,8 @@ <h3 id="_why_was_this_all_so_hard">Why Was This All So Hard?</h3>
570589< div class ="sect2 ">
571590< h3 id ="_what_to_do_if_you_already_have_django "> What to Do If You Already Have Django</ h3 >
572591< div class ="paragraph ">
573- < p > So what should you do if you want to apply some of the patterns in this book
592+ < p >
593+ So what should you do if you want to apply some of the patterns in this book
574594to a Django app? We’d say the following:</ p >
575595</ div >
576596< div class ="ulist ">
@@ -610,7 +630,8 @@ <h3 id="_what_to_do_if_you_already_have_django">What to Do If You Already Have D
610630< div class ="sect2 ">
611631< h3 id ="_steps_along_the_way "> Steps Along the Way</ h3 >
612632< div class ="paragraph ">
613- < p > Suppose you’re working on a Django project that you’re not sure is going
633+ < p >
634+ Suppose you’re working on a Django project that you’re not sure is going
614635to get complex enough to warrant the patterns we recommend, but you still
615636want to put a few steps in place to make your life easier, both in the medium
616637term and if you want to migrate to some of our patterns later. Consider the following:</ p >
@@ -657,7 +678,8 @@ <h3 id="_steps_along_the_way">Steps Along the Way</h3>
657678</ table >
658679</ div >
659680< div class ="paragraph ">
660- < p > For more thoughts and actual lived experience dealing with existing
681+ < p >
682+ For more thoughts and actual lived experience dealing with existing
661683applications, refer to the < a href ="/book/epilogue_1_how_to_get_there_from_here.html "> epilogue</ a > .</ p >
662684</ div >
663685</ div >
@@ -680,7 +702,7 @@ <h3 id="_steps_along_the_way">Steps Along the Way</h3>
680702</ div >
681703< div id ="footer ">
682704< div id ="footer-text ">
683- Last updated 2020-03-17 09:07:44 UTC
705+ Last updated 2020-03-20 13:47:19 UTC
684706</ div >
685707</ div >
686708< style >
0 commit comments