2017-12-30 24 views
0

TextFieldの列に鮮明なフォームがレイア​​ウトされているテキストボックスが大きすぎるため、あまりにも多くの画面領域を占めています。ユーザーは、必要に応じて下の枠線をドラッグして背を高くすることができますが、最小サイズは大きすぎます。私はデフォルトの高さを4行程度にしたいと思います。Djangoのシンプルなフォームを使用して、TextFieldのテキストボックスをどのように縮小しますか?

私はいくつかのアイデアを試しましたが、関連する投稿はありましたが、何も機能しませんでした。テキストボックスは同じ高さと高すぎました。ここで

は私が現時点で働いているモデルである:

class Brand(models.Model): 
    cTitle   = models.CharField(
         'brand name', max_length = 48, db_index = True) 
    bWanted   = models.BooleanField(
         'want anything from this brand?', default = True) 
    bAllOfInterest = models.BooleanField(
         'want everything from this brand?', default = True) 
    cLookFor  = models.TextField(
         'Considered a hit if this text is found ' 
         '(each line evaluated separately, ' 
         'put different look for tests on different lines)', 
         null=True, blank = True) 
    iStars   = IntegerRangeField(
         'desireability, 10 star brand is most desireable', 
         min_value = 0, max_value = 10, default = 5) 
    cComment  = models.TextField('comments', null = True, blank = True) 
    cNationality = CountryField("nationality", null = True) 
    cExcludeIf  = models.TextField(
         'Not a hit if this text is found ' 
         '(each line evaluated separately, ' 
         'put different exclude tests on different lines)', 
         null=True, blank = True) 
    iLegacyKey  = models.PositiveIntegerField('legacy key', null = True) 
    tLegacyCreate = models.DateTimeField('legacy row created on', 
         null=True, blank = True) 
    tLegacyModify = models.DateTimeField('legacy row updated on', 
         null=True, blank = True) 
    iUser   = models.ForeignKey(User, verbose_name = 'Owner', 
         on_delete=models.CASCADE) 
    tCreate   = models.DateTimeField('created on', auto_now_add= True) 
    tModify   = models.DateTimeField('updated on', auto_now = True) 
    # 

    def __str__(self): 
     return self.cTitle 

    class Meta(): 
     verbose_name_plural = 'brands' 
     ordering   = ('cTitle',) 
     db_table   = verbose_name_plural 

しかし、唯一のこれらのフィールドは、フォーム上にある:

tModelFields = (
    'cTitle', 
    'bWanted', 
    'bAllOfInterest', 
    'cLookFor', 
    'iStars', 
    'cComment', 
    'cNationality', 
    'cExcludeIf') 

指導をいただければ幸いです。

+0

あなたはそのフィールド –

答えて

0

ドキュメントに基づいてcrispy_formsを使用しているので、Layoutsを使用して、テンプレートに追加されるフィールドの「要素」の属性を定義することができます。as it is explained here in the documentation

このようなものになるだろう。この場合

Field('cExcludeIf', rows='4')

+0

のためにあなたの 'models.py'に与えているものを私を共有することができ、私は入力に感謝。私はそれを試してみました。私はフィールド( 'cExcludeIf'、行= '2')を設定しますが、ページ上のテキストボックスはまだ10行高いです。 –

関連する問題