In Django application, several views may contain similar db queries.
For instance, a query for all entities where is_active = True and is_online = True.
During refactoring, such duplicate calls need to be moved into a function and the question is where this filter/query function should better be placed.
1) Into definition of class/entity? But should object “know” about it’s own filter methods?
This seems to be a typical solution, but may be not a good design since selection feels to be a feature external to object. On the other hand, such methods inside object don’t create side-effects and seem pretty safe.
2) Into some module/namespace dealing with filtering, like filter.Users, filter.Entities?
Or somewhere else?
Whats the best practice?
This is exactly what model Managers are for.