I see in the Django documentation :
Model Instance reference : Creating objects
You may be tempted to customize the model by overriding the
__init__
method. If you do so, however, take care not to change the calling signature as any change may prevent the model instance from being saved.
Rather than overriding__init__
, try using one of these approaches:
- Add a classmethod on the model class.
- Add a method on a custom manager (usually preferred)
Why is the second solution "usually preferred" ?
In a situation where I have a model B
which extends a model A
through a OneToOne
relation, and I want to create a method generating a B
object which generates the corresponding A
object as well, how is it "better" to use a custom manager as suggested, given I'll probably not use this manager for anything other than what is provided by default manager ?