声明:我是一名初学者,拥有python和Django,但拥有Drupal编程经验。初学者:Django ModelForm替代小部件
我如何可以覆盖这个默认的窗口小部件:
#models.py
class Project(models.Model):
color_mode = models.CharField(max_length=50, null=True, blank=True, help_text='colors - e.g black and white, grayscale')
在我的形式选择框?以下是好还是我错过了什么?
#forms.py
from django.forms import ModelForm, Select
class ProjectForm(ModelForm):
class Meta:
model = Project
fields = ('title', 'date_created', 'path', 'color_mode')
colors = (
('mixed', 'Mixed (i.e. some color or grayscale, some black and white)'),
('color_grayscale', 'Color/Grayscale'),
('black_and_white', 'Black and White only'),
)
widgets = {'color_mode': Select(choices=colors)}
阅读https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets后,我很失落,因为例如只讨论TextArea和小部件的讨论似乎排除的ModelForm。
谢谢!