本文介绍了如何在Django Models中设置textField中的行,列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个模型

  summary = models.TextField()
/ pre>

但是我想只有4行和15列。



如果我这样做我需要再次安装数据库。

解决方案

TextField 字段类型,默认情况下由 ModelForm 使用时,使用 Textarea 小部件。 处理后端存储空间,,前端编辑。



所以你需要用你的字段指定你要去的小部件。您要创建一个,并根据:

  from django import forms 

class MyForm(forms.ModelForm):
class Meta:
model = MyModel
widgets = {
'summary':forms.Textarea(attrs = {'rows':4,'cols':15}),
}


I have this Model

summary         = models.TextField()

But I want to have only 4 rows and 15 columns.

Also if I do that do I need to install database again or not.

解决方案

TextField is a type of field, which when used by a ModelForm by default uses the Textarea widget. Fields deal with backend storage, widgets with front-end editing.

So you need to specify the widget you want to go with your field. You want to create a ModelForm and specify the widget you want to use, per the documentation:

from django import forms

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        widgets = {
          'summary': forms.Textarea(attrs={'rows':4, 'cols':15}),
        }

这篇关于如何在Django Models中设置textField中的行,列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:39
查看更多