[Grok-dev] class-level versus instance-level attributes for schema

Martijn Faassen faassen at infrae.com
Fri Oct 20 07:53:17 EDT 2006

Philipp von Weitershausen wrote:
> Martijn Faassen wrote:
>>>> But we'd need to poke in a custom __init__ into the class during 
>>>> grok-time, which could be considered icky (then again, poking in 
>>>> class-level attributes could be considered as icky as well).
>>> Why don't me make that the default grok.Model.__init__? In the rare 
>>> case that people need to do their own initialization, they can choose 
>>> to use super() (or not).
>> That sounds like a reasonable strategy, though I'd like to explore 
>> some alternatives:
>> An alternative would be to have a separate SchemaModel object and do 
>> it in the __init__ there, but another source of confusion could arise: 
>> people using class fields on a non-schema model and having it not 
>> working.
>> What we could also do is create an __init__ based on the form, but 
>> only poke it in if the grok.Model is not defining one itself. That 
>> might be too magic however.
> I prefer as little magic as necessary. I think the "super" strategy is 
> easily documented:
>   * either you don't implement your custom __init__
>   * or if you do, you
>     o either have to set reasonable default values for the fields
>     o or make sure to call the super __init__ to have it done for you

Okay, +1



More information about the Grok-dev mailing list