本文介绍了如何使用酥脆的表格在一行上显示Django SelectDateWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一行上显示使用Django SelectDateWidget渲染的3个选择字段.当我使用脆皮形式时,它们都位于单独的行上.有没有办法使用布局助手来实现这一目标?

I am trying to display the 3 select fields that are rendered out using Django SelectDateWidget on one line. When I use crispy forms, they are all on separate rows. Is there a way to use the Layout helper to achieve this?

谢谢!

class WineAddForm(forms.ModelForm):
hold_until = forms.DateField(widget=SelectDateWidget(years=range(1950, datetime.date.today().year+50)), required=False)
drink_before = forms.DateField(widget=SelectDateWidget(years=range(1950, datetime.date.today().year+50)), required=False)

helper = FormHelper()
helper.form_method = 'POST'
helper.form_class = 'form-horizontal'
helper.label_class = 'col-lg-2'
helper.field_class = 'col-lg-8'
helper.add_input(Submit('submit', 'Submit', css_class='btn-wine'))

helper.layout = Layout(
    'name',
    'year',
    'description',
    'country',
    'region',
    'sub_region',
    'appellation',
    'wine_type',
    'producer',
    'varietal',
    'label_pic',
    'hold_until',
    'drink_before',
)

class Meta:
    model = wine
    exclude = ('user', 'slug', 'likes')

推荐答案

将此操作添加到您的SelectDateWidget字段的布局中:

Add this to your layout for your SelectDateWidget fields:

MultiWidgetField('field_name', attrs=({'style': 'width: 33%; display: inline-block;'}))

这篇关于如何使用酥脆的表格在一行上显示Django SelectDateWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:23