本文介绍了Django-Admin:CharField as 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'字段?
how to assign TextArea widget to 'descr' field in admin interface?
upd:
在管理
使用ModelForm的好主意。
Good idea to use ModelForm.
推荐答案
您将必须创建一个 forms.ModelForm
,将描述您希望显示 descr
字段的方式,然后告诉 admin.ModelAdmin
以使用该表单。例如:
You will have to create a forms.ModelForm
that will describe how you want the descr
field to be displayed, and then tell admin.ModelAdmin
to use that form. For example:
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
管理员的
记录在官方Django文档中。以下是。表单
属性。 ModelAdmin
The form
attribute of admin.ModelAdmin
is documented in the official Django documentation. Here is one place to look at.
这篇关于Django-Admin:CharField as TextArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!