Re:Django Styleguide
by Alir3z4 on Wednesday January 11, 2023 @09:37AM
(#34338913)
Reading through this, the majority of points could be "Not to do" stuff.
I've worked on many small to mid and large code bases. Many many apps and different logics and annoyingly enterprise. The majority of things mentioned in this document are plain bad.
Probably works for the company behind it.
I can explain the reason for all of them, but particularly "Service Layer" is something I don't see any fit in the realm of Django.
The service layer doesn't go well with Django, especially the way it has been described in this style guide.
If I'm building an API endpoint, why would I want to implement the validations and business logic in some other class/function? Why can't that be done in the serializers? why not lock the database models by properly Meta.constraints or permission classes etc..?
This shows DRF serializers are being built as subclass inside the view class. Such an annoying take to me. Why? Why specifically have to have the Serializers, Paginators classes, and all the stuff indented into the API view class?
DRF ModelSerializers are automatically built around the validation definition of DB.models.Model, using the service layer means you lose all of that. The same is true for Django Forms or Django Admin or anything in Django. Django starts from models and ends with models.
Working on small to mid-size (_let alone large Django projects_), the worst I can do is to follow such guidelines. Swimming against the river stream.
The settings/* structure is a mess in itself as well. Every project doing 1 setting per environment ended up having tens of them to support different ends and lots of confusion in what is doing what.
Service Layer is not a fit for Django and it will never be (_at least the way Django is atm_).
Do yourself a favor and don't follow such guidelines, just because they have thousands stars doesn't make them valid.
Looking at code samples, it doesn't look like Django or how Django projects look like.
Django is simple, Views, Serializers, Models, Forms and that's it. All of them work in harmony and trying to cut them through with such patterns will cause you to lose many benefits of the framework.
Probably works for the company behind it.
I can explain the reason for all of them, but particularly "Service Layer" is something I don't see any fit in the realm of Django. The service layer doesn't go well with Django, especially the way it has been described in this style guide.
If I'm building an API endpoint, why would I want to implement the validations and business logic in some other class/function? Why can't that be done in the serializers? why not lock the database models by properly Meta.constraints or permission classes etc..?
This shows DRF serializers are being built as subclass inside the view class. Such an annoying take to me. Why? Why specifically have to have the Serializers, Paginators classes, and all the stuff indented into the API view class?
DRF ModelSerializers are automatically built around the validation definition of DB.models.Model, using the service layer means you lose all of that. The same is true for Django Forms or Django Admin or anything in Django. Django starts from models and ends with models.
Working on small to mid-size (_let alone large Django projects_), the worst I can do is to follow such guidelines. Swimming against the river stream.
The settings/* structure is a mess in itself as well. Every project doing 1 setting per environment ended up having tens of them to support different ends and lots of confusion in what is doing what.
Service Layer is not a fit for Django and it will never be (_at least the way Django is atm_).
Do yourself a favor and don't follow such guidelines, just because they have thousands stars doesn't make them valid.
Looking at code samples, it doesn't look like Django or how Django projects look like.
Django is simple, Views, Serializers, Models, Forms and that's it. All of them work in harmony and trying to cut them through with such patterns will cause you to lose many benefits of the framework.
edit: typos