4 ms·
This approach is definitely swimming against the tide with Django. I’ve spent a lot of time with Django, and a lot of time trying to work out how to best build
by KyeRussell 4y ago
This approach is definitely swimming against the tide with Django. I’ve spent a lot of time with Django, and a lot of time trying to work out how to best build complex systems with it. I don’t think that for Django’s case the answer is anything close to being as simple as “don’t let the models go anywhere”, unfortunately. Though I am really intrigued to try it and see how it goes.
- matsemann 4y agoI've in some apps tried to use a pattern where only certain files are allowed to touch the model classes (selectors.py, services.py). Something queried from the selector is mapped to a dumb pydantic object before being returned. To change something you need to call a function in services, can no longer modify a value on the object and call save. Some drawbacks is that it can cost you a few queries when you want to select related. Or you need to make a specific function for selecting the relation, but then have a different pydantic return type now with that value prefetched. So a bit more boilerplate, but no longer any surprises