0

I'm not sure to understand the actual purpose of using a create_object() method in a custom manager, rather than directly in the model, when I need to override the default Class.objects.create() method.

The only difference I see is how I would call it:

  • Class.create_object() if the create_object() method is in the model
  • Class.objects.create_object() if the create_object is a custom manager method.

However, I suppose the latter is the right thing to do, based on examples I can see from Django (with create_user for example). I just would like to understand why.

Thanks!

David Dahan
  • 10,576
  • 11
  • 64
  • 137
  • Similar questions: https://stackoverflow.com/questions/17320333 & https://stackoverflow.com/questions/7692487/ – Alasdair Jan 15 '18 at 16:43
  • Thanks, the accepted answer on that post is very interesting. However,I think it does not directly answer the question for the object creation case. (I actually knew about the benefits of custom querysets). – David Dahan Jan 15 '18 at 16:51
  • I'm not sure what's different about the object creation case. The reasons like following Django convention, code re-usability, not polluting the instance namespace, and so on still apply. – Alasdair Jan 15 '18 at 17:04
  • 1
    @Alasdair Oh! I didn't see there was two links in your comment. I just read the second one and understand better now :) – David Dahan Jan 18 '18 at 10:23

0 Answers0