Thanks Ryan,
Exactly,
as explained below:
On Sat, Nov 12, 2022 at 5:49 PM Ryan Nowakowski <ryan@fattuba.com> wrote:
Hey Amir,--
Django best practice is to put all common query methods in the model manager class instead of the model class itself.
- Ryan NOn November 11, 2022 12:30:36 PM CST, Amir Jamshidi <amir.jamshidijam@gmail.com> wrote:Hi,I tried to write a classmothods/ instance method in a Model in order to run most common query from the model but got errors like below :""AttributeError: Manager isn't accessible via ... instances""example code:class Profile(model.Model):name = model.Charfield(...)address = model.Charfield(...)....@classmethoddef count_of_users(cls):return cls.objects.all() #example querydef all_users(self):return self.objects....My purpose is to have most common and important queries in a method to be called within application. (Its a good way for documenting most common queries as well).What is the best practice for this case?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/E69A0C3B-167B-4799-B19D-7E33DB56BCB1%40fattuba.com.
___________________________________
Amir JamshidiJam
Computer Engineering at Shiraz UniversityAmir JamshidiJam
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAC-x6WY25sTbMrB4nMnscXEYZehiQ%2BMbWtjxAiyKhpqYOcj3sA%40mail.gmail.com.
No comments:
Post a Comment