billyJoe
billyJoe

Reputation: 2064

How to know where to save model method

I have a simple question. Suppose products with associtaed recommandations. I'd like to get a product recommandation then it's a simple model method (i.e: get_product_recommandation()) but I do not know to put it. In my recommandations models.py or in models.py in the product folder ?

Upvotes: 0

Views: 28

Answers (2)

aman kumar
aman kumar

Reputation: 3156

you can make custom querysets or manger to put database query realted function. put model update function in model file.

Upvotes: 0

ben432rew
ben432rew

Reputation: 1902

I'd put it in your models.py in the product app like:

Class Product(models.Model):

    ...

    def get_product_recommandation(self):
        return self.recommendation_set.all()  #  or whatever

Upvotes: 2

Related Questions