Opened 17 years ago
Closed 16 years ago
#5648 closed (wontfix)
__init__ of Models not overrideable
Description ¶
Apparently django is calling __init__
for models created from database data. This makes it impossible to override the constructor that has a different signature.
It would make more sense if the database API is creating a verbatim instance of the class using object.__new__(Model)
and updating the attributes. It would also be possible to add a construct
method that is called when a model is assembled from database data.
I can provide a patch if wanted.
Change History (2)
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Django is using the initialisation function on a class to create instances of that class. That's what
__init__
is for. You can easily override it, but you have to be able to accept the way a Model class is called, which means accepting things matching the current signature. That's true whenever you subclass something: if you pass it to something that expects the parent, you have to match the parent's initialisation interface.