免責事項:私は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')
:
どのように私は、このデフォルトのウィジェットを上書きすることができますか?次のことはOKですか、何か不足していますか?例のみのTextAreaを説明し、ウィジェットの議論はのModelFormを除外するように思われるので、
#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を読んだ後、私は失われています。
ありがとうございます!