You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rewriting the first repository test was a minimal change, just rewriting
70
70
some raw SQL with a call to the Django ORM/QuerySet language:
@@ -160,7 +160,7 @@ help minimize boilerplate for this sort of thing.]
160
160
161
161
==== Custom Methods on Django ORM Classes to Translate to/from Our Domain Model
162
162
163
-
Those custom methods look something like this:
163
+
Those custom methods ((("object-relational mappers (ORMs)", "Django, custom methods to translate to/from domain model")))((("domain model", "Django custom ORM methods for conversion")))look something like this:
164
164
165
165
[[django_models]]
166
166
.Django ORM with custom methods for domain model conversion (src/djangoproject/alloc/models.py)
@@ -220,14 +220,14 @@ class OrderLine(models.Model):
220
220
221
221
222
222
NOTE: As in <<chapter_02_repository>>, we use dependency inversion.
223
-
The ORM (Django) depends on the model, and not the other way around.
223
+
The ORM (Django) depends on the model, and not the other way around.((("Repository pattern", "with Django", startref="ix_RepoDjango")))((("Django", "Repository pattern with", startref="ix_DjangoRepo")))
224
224
225
225
226
226
227
227
=== Unit of Work Pattern with Django
228
228
229
229
230
-
The tests don't change too much:
230
+
The tests((("Unit of Work pattern", "with Django", id="ix_UoWDjango")))((("Django", "Unit of Work pattern with", id="ix_DjangoUoW"))) don't change too much:
@@ -318,13 +318,13 @@ class DjangoUnitOfWork(AbstractUnitOfWork):
318
318
instrumenting the domain model instances themselves, the
319
319
`commit()` command needs to explicitly go through all the
320
320
objects that have been touched by every repository and manually
321
-
update them back to the ORM.
321
+
update them back to the ORM.((("Unit of Work pattern", "with Django", startref="ix_UoWDjango")))((("Django", "Unit of Work pattern with", startref="ix_DjangoUoW")))
322
322
323
323
324
324
325
325
=== API: Django Views Are Adapters
326
326
327
-
The Django _views.py_ file ends up being almost identical to the
327
+
The Django _views.py_ file ends ((("views", "Django views as adapters")))((("adapters", "Django views")))((("Django", "views are adapters")))((("APIs", "Django views as adapters")))up being almost identical to the
328
328
old _flask_app.py_, because our architecture means it's a very
329
329
thin wrapper around our service layer (which didn't change at all, by the way):
330
330
@@ -370,7 +370,7 @@ def allocate(request):
370
370
=== Why Was This All So Hard?
371
371
372
372
OK, it works, but it does feel like more effort than Flask/SQLAlchemy. Why is
373
-
that?
373
+
that?((("Django", "using, difficulty of")))
374
374
375
375
The main reason at a low level is because Django's ORM doesn't work in the same
376
376
way. We don't have an equivalent of the SQLAlchemy classical mapper, so our
@@ -397,7 +397,7 @@ around the workflow of state changes. The Django admin bypasses all of that.
397
397
=== What to Do If You Already Have Django
398
398
399
399
So what should you do if you want to apply some of the patterns in this book
400
-
to a Django app? We'd say the following:
400
+
to a Django app?((("Django", "applying patterns to Django app"))) We'd say the following:
401
401
402
402
* The Repository and Unit of Work patterns are going to be quite a lot of work. The
403
403
main thing they will buy you in the short term is faster unit tests, so
@@ -430,7 +430,7 @@ your _models.py_, which you can then keep as minimal as possible.
430
430
Suppose you're working on a Django project that you're not sure is going
431
431
to get complex enough to warrant the patterns we recommend, but you still
432
432
want to put a few steps in place to make your life easier, both in the medium
433
-
term, and if you want to migrate to some of our patterns later. Consider the following:
433
+
term, and if you want to migrate to some of our patterns later.((("Django", "applying patterns to Django app", "steps along the way"))) Consider the following:
434
434
435
435
* One piece of advice we've heard is to put a __logic.py__ into every Django app,
436
436
from day one. This gives you a place to put business logic, and to keep your
@@ -454,5 +454,5 @@ NOTE: We'd like to give a shout out to David Seddon and Ashia Zawaduk for
454
454
stop us from saying anything really stupid about a topic we don't really
455
455
have enough personal experience of, but they may have failed.
456
456
457
-
For more thoughts and actual lived experience dealing with existing
457
+
For more ((("Django", startref="ix_Django")))thoughts and actual lived experience dealing with existing
458
458
applications, refer to the <<epilogue_1_how_to_get_there_from_here>>.
Copy file name to clipboardExpand all lines: appendix_ds1_table.asciidoc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
[appendix]
3
3
== Summary Diagram and Table
4
4
5
-
Here's what our architecture looks like by the end of the book:
5
+
Here's what our architecture looks((("architecture, summary diagram and table", id="ix_archsumm"))) like by the end of the book:
6
6
7
7
[[recap_diagram]]
8
8
image::images/apwp_aa01.png["diagram showing all components: flask+eventconsumer, service layer, adapters, domain etc"]
@@ -53,6 +53,6 @@ __Translate external inputs into calls into the service layer.__
53
53
| Web | Receives web requests and translates them into Commands, passing them to the Internal Message Bus.
54
54
| Event consumer | Reads events from the external message bus and translates them into commands, passing them to the internal message bus.
55
55
56
-
| N/A | External message bus (message broker) | A piece of infrastructure that different services use to intercommunicate, via events.
56
+
| N/A | External message bus (message broker) | A piece of infrastructure that different services use to intercommunicate, via events.((("architecture, summary diagram and table", startref="ix_archsumm")))
0 commit comments