Answer the question
In order to leave comments, you need to log in
How to properly organize code in Django?
Hello! The question is about the nuances of following the SOLID principles in Django.
There is a model (schematically) with a method
class Product(models.Model):
name = models.CharField()
type = models.CharField(choices=PRODUCT_CHOICES)
def process_new_order(self, *args, **kwargs):
if self.type == 'type one':
""" do order """
if self.type == 'type two':
""" do another order """
Answer the question
In order to leave comments, you need to log in
In essence, you have a "product type" business entity, each object of which implements its own way of doing "do order". Perhaps you should make a ProductType model and have a process_new_order(order: Product) method. Or perhaps it will be enough to make not a django model, but just a class in python, using the Strategy pattern.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question