I have been working on this too, in my case, I always make the service's
layer, fat view or fat serializer or model for me, they are very difficult
to test them.
For example: unitary test, if you have your business  logic in serializer
or model, it could be difficult to test, you have to mock many things.
If you have a service's layer between your view and ORM, if you need to
test it, you only need to mock the query, and there are some good packages
for it.



El vie, 24 mar 2023 a las 14:23, Tj Johnson (<t22thejohn...@gmail.com>)
escribió:

> I find that this becomes less and less of a concern the more you learn the
> frameworks, you aren't limited to implementing logic in models or views,
> although that is how I started, and other developers too.  You can also
> extend and customize serializers, or fields, or validators, or model
> managers, or permissions, or mixins, or middleware etc. there are also
> hooks.  It's just a matter of choosing the appropriate location of the
> business logic.
>
> But I think if the developer doesn't know enough, I'd prefer to see "fat
> views"
>
> On Tuesday, March 21, 2023 at 7:24:23 PM UTC-4 Pascal Schäfer wrote:
>
>> Hello,
>>
>> I'm currently working on a project using Django or Django Rest Framework
>> to implement an API. Now the question came to me what is the best practice
>> implementation when it comes to business logic? Are fat models, fat views,
>> service layers or something else the best practice?
>>
>> I did already some research and was reading different articles about it
>> and it seems that a lot of people go the way of a service layer to
>> implement a three tier MVC, but I was also reading that implementing an
>> extra service layer could lead to circumvent automatism that drf would do
>> for you. Is there any advice that you can give?
>>
>> These articles are some that I read before I asked here:
>> https://itecnote.com/tecnote/python-django-rest-framework-business-logic/
>>
>> https://aliashkevich.com/business-logic-in-django-rest-framework-applications/
>> https://www.b-list.org/weblog/2020/mar/16/no-service/
>>
>> Especially the last one is completely against a service layer.
>>
>> Thanks in advance!
>>
>> Best regards,
>>
>> Pascal
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/93fe5102-de8f-4929-b517-5301d7d74873n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/93fe5102-de8f-4929-b517-5301d7d74873n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAOw1d1dhHcrUSdZz%2BNgEj5GhNyVFgytJrJPHyTRv_v0bsFY63A%40mail.gmail.com.

Reply via email to