python - Automatically passing extra attributes to Widget -


I have a custom model field, which can contain the 'chain' argument. Chain from

 : chain = chainfield (object): df __int __ (self, * algs, ** quarj): chain = quartz ('Chain', false) if the chain: self. Chain = Chain Del Quad ['chain'] Super (self .__ class __.__ MRU __ [2], self) .__ init __ (* args, ** kwargs) class DateTimeField (ChainField, models.DateTimeField): pass  

And now the question: How can I automatically pass the 'series' argument of the model class to the widget class when launching ModelForm? I think this is the attribute of the 'class =' ​​chain xxx "'form field in html.

Override __init __ of ModelForm like this:

  class MyClass (ModelForm): def __init __ (auto, * args, * * Kwargs): Super (MyClass, itself) .__ init __ (* Args, ** kwargs) chain_value = self.fields ['name_of_the_field']. Chain self.fields ['name_of_the_field']. Widget = custom widget (series = chain_ value )  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -