-
-
Save k4ml/8699461 to your computer and use it in GitHub Desktop.
class Messaging(object): | |
def __init__(self, user, sender, receiver, message): | |
self.user = user | |
self.sender = sender | |
self.receiver = receiver | |
self.message = message | |
def send(self): | |
required_points = self.get_required_points() | |
if required_points > self.user.points: | |
raise Exception('Not enough points') | |
return self.backend.send(self.sender, self.receiver, self.message) |
hi @k4ml, I'm new to django/python and I'm looking for articles, books, etc, about the strategy of using pure python objects to place complex business logic. My biggest difficult now is about django project structures. Where this kind of classes should be placed?
do you have any sources related to this?
hi @k4ml, I'm new to django/python and I'm looking for articles, books, etc, about the strategy of using pure python objects to place complex business logic. My biggest difficult now is about django project structures. Where this kind of classes should be placed?
do you have any sources related to this?
hi gcaraciolo
Service objects are plain old Python objects (POPOs) that encapsulate a
service or interactions with a system. They are usually kept in a separate
file named services.py or utils.py.
I'm in 2024 and enjoying this thread. Thank you!
For some reason one of my comment here was lost and I'm not in the mood of retyping it again. Basically the class is what being referred as domain layer in languages such as Java or C#. The class should be plain python object (POPO) that does not contain any dependencies to the framework (in theory basically, in practice we still has to couple it at least to the django ORM). This mean it possible for you to take the class out of your django project and still being able to instantiate it by just passing it's required parameters.
Example of such class - gist.github.com/k4ml/8699461.