Create dynamic fields in ModelForm (Django)

How do I create fields in ModelForm on the go?

For example, I want to create 3 textboxes (because there are 3 entries in the database table)

 ID  Name   Value 
------------------
 1   Alpha  10   
 2   Beta   91    
 3   Char   800  

How do I display it in this way to the user? Does it involve the _init definition? Is it possible to do a for loop of objects in your model form class to retrieve its values and convert them to a field to be displayed? Appreciate any suggestions.

Alpha 

[textbox]
______
Beta

[textbox]

____

etc..

[Submit]

Here is what I tried to do in the def init of the modelform:

self.fields['myfield'].widget = forms.Textarea()

Can't seem to give me the output, do mind my weak understanding of certain django concepts.

6
задан Pierre de LESPINAY 23 April 2012 в 08:10
поделиться