使用Django crispy表单,如何缩小TextField的文本框?

问题描述 投票:0回答:1

TextField列的酥脆表单的文本框对于我的应用来说太高了,它们占用了太多的屏幕空间。如果需要,用户可以通过拖动底部框架线使它们更高,但最小尺寸太高。我希望默认高度为4行左右。

我尝试了一些我从相关帖子中获得的想法,但没有任何效果 - 文本框仍然是相同的高度和太高。

这是我目前正在制作的模型:

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' )

指导将不胜感激。

django resize textfield django-crispy-forms
1个回答
0
投票

由于您根据他们的文档使用crispy_forms,您可以使用Layouts来定义将添加到模板as it is explained here in the documentation的字段“元素”的某些属性。

在这种情况下,它将是这样的:Field('cExcludeIf', rows='4')

© www.soinside.com 2019 - 2024. All rights reserved.