Django-Admin:CharField为TextArea

我有

class Cab(models.Model):
    name  = models.CharField( max_length=20 )
    descr = models.CharField( max_length=2000 )

class Cab_Admin(admin.ModelAdmin):
    ordering     = ('name',)
    list_display = ('name','descr', )
    # what to write here to make descr using TextArea?

admin.site.register( Cab, Cab_Admin )

如何分配TextArea小部件到’descr’字段在管理界面?

upd:
仅在管理界面!

好主意使用ModelForm。

您将必须创建一个forms.ModelForm,它将描述您希望如何显示descr字段,然后告诉admin.ModelAdmin使用该表单。例如:

from django import forms
class CabModelForm( forms.ModelForm ):
    descr = forms.CharField( widget=forms.Textarea )
    class Meta:
        model = Cab

class Cab_Admin( admin.ModelAdmin ):
    form = CabModelForm

admin.ModelAdmin的form属性记录在官方Django文档中。这里是one place to look at

http://stackoverflow.com/questions/430592/django-admin-charfield-as-textarea

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:Django-Admin:CharField为TextArea