在Django模型选择字段中显示月份名称而不是月份号

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

SAPAdjustment中的acct_per_num列”包含月份号。下面的代码提供了一个带有月份数字(1,2,3)的下拉列表,但我想使用月份名称(January,February,March)。

forms.py

class SAPReconForm(forms.Form):
    month = forms.ModelChoiceField(queryset=SAPAdjustment.objects.values_list('acct_per_num',flat=True).distinct(), empty_label=None)

models.py

class SAPAdjustment(models.Model):
    acct_per_num =  models.IntegerField( blank=True,null=True, verbose_name =_('Month'),help_text=_('Month'))
django django-models django-forms django-orm
1个回答
0
投票

使用calendar--(pydocs)模块生成calendar为,

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