0
簡單地說,我寫的:如何在模型中定義的控件屬性
# forms.py
class NoteForm(ModelForm):
def __init__(self, *args, **kwargs):
super(NoteForm, self).__init__(*args, **kwargs)
#add attributes to html-field-tag:
self.fields['content'].widget.attrs['rows'] = 3
self.fields['title'].widget.attrs['size'] = 20
class Meta:
model = Note
fields = ('title','content')
要添加或修改某些屬性的HTML標記字段。
但在這個時候,我將不得不直接做在注模型models.py
#models.py
class Note(models.Model):
title = models.CharField(max_length=100)
content = models.TextField(max_length=255)
#how to define the fields.widget.attrs here ?????
僅供參考:爲什麼呢?因爲會爲
NotesFormSet = inlineformset_factory(NoteBook, Note, extra=10)
工作要添加增加了許多時的注意事項/編輯筆記本
注意:這不是Django管理
如果我不是給你足夠的背景下,評論PLZ,任何提示是apreciated =')
OMG!它的工作原理:D。謝謝! – panchicore 2009-10-12 17:05:55