On Jul 14, 2012, at 6:37 PM, Russell Keith-Magee wrote:

> 
> My only concern is:
> 
>> We could store which fields have these hooks upon ModelBase.__new__
>> construction and so skip most fields and overhead in __init__.
> 
> I'm not sure if I'm misreading your intentions here, but just to be
> sure -- I'd like to avoid explicitly naming certain field types as
> "special" in ModelBase if at all possible. If we explicitly name
> certain fields in ModelBase, then it means that third-parties with the
> same requirement won't be able to exploit the same API entry point. In
> the case of GenericForeignKey specifically, it also means that we
> would be introducing a dependency (even if it was name-only) on
> contrib into core -- which is something we've been trying to move away
> from.



I think Jeremy means doing something like this in ModelBase.__new__:


    meta.fields_needing_init = [field for field in fields if hasattr(field, 
'model_pre_init')]


And in ModelBase.__init__:


    for field in self._meta.fields_needing_init:
        field.model_pre_init(*args, **kwargs)


This way, in ModelBase.__init__, only the fields that actually need to be 
initialized have this method called.


-andy

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to