Confused on when and what to put in managers.py, querysets.py, services.py, and selectors.py
I am very confused on the distinction between these different files. I feel like querysets.py is essentially just moving logic away from managers.py. And how is selectors.py different from querysets.py? Both are querying information from the database.
And then services.py - I've read several places that having a service lay is a bad idea (ref. https://www.b-list.org/weblog/2020/mar/16/no-service/). Then where do I put service/business logic functions and methods?
For example, I have a very difficult time knowing if this code should reside in managers.py on the model itself inside a method, or in the services.py file.
def like_toggle(user):
if user in comment.dislikes.all():
comment.dislikes.remove(user)
if user in comment.likes.all():
comment.likes.remove(user)
else:
comment.likes.add(user)
comment.save()
def dislike_toggle(user):
if user in comment.likes.all():
comment.likes.remove(user)
if user in comment.dislikes.all():
comment.dislikes.remove(user)
else:
comment.dislikes.add(user)
comment.save()
def report_comment():
if not comment.is_flagged:
comment.is_flagged = True
comment.save()
Posted Nov 2, 2023, 1:32 AM UTC
10