[Django]-Django model method vs custom manager

3πŸ‘

βœ…

In your case specifically, you should go with the non-manager version, if you go with the custom manager you’ll be adding a method as well (not working over the manager QuerySet), and also you will have to provide the user parameter.

Using a method left the user instance the responsibility of finding users nears to itself.

And not to mention you have to write more code using the first option and it would be slower too.

user.user_in_radiuos.find_users_in_radius(user)  # Two attribute lookpus, redundance: calling object == parameter.
user.users_in_search_radius()  # Clean, no redundance.

3πŸ‘

You only need to define a custom manager when you want to modify the default manager ( objects ) or add extra manager methods (which are not present in default manager).

So, if you can use the default manager without having to modify it then why reinventing the wheel.

πŸ‘€Ahtisham

Leave a comment