【发布时间】:2012-04-10 07:57:10
【问题描述】:
免责声明:我是 python 和 Django 的初学者,但有 Drupal 编程经验。
我怎样才能覆盖这个的默认小部件:
#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。
谢谢!
【问题讨论】:
标签: django django-models