2015-10-23 26 views
2

这里很奇怪的问题。我使用的是django-choices模块(V1.3),并定义了一组选项,如下所示:Django选择:我的一个选择项目将标签复制到值

class BreaktimeChoices(DjangoChoices): 
    BREAKTIME_NONE = ChoiceItem(value=datetime.time(0,0), label=_('none')) 
    BREAKTIME_15_MIN = ChoiceItem(value=datetime.time(0,15), label=_('15 minutes')) 
    BREAKTIME_30_MIN = ChoiceItem(value=datetime.time(0,30), label=_('30 minutes')) 
    BREAKTIME_45_MIN = ChoiceItem(value=datetime.time(0,45), label=_('45 minutes')) 
    BREAKTIME_1_HOUR = ChoiceItem(value=datetime.time(1,0), label=_('1 hour')) 

当我然后把它变成一个形式(至选择输入),我注意到标签是正确的,但BREAKTIME_NONE的值为'无'(而不是预期的00:00:00)。当打印BreaktimeChoices.choices我得到这个:

((<django.utils.functional.__proxy__ object at 0x7f995c306f50>, <django.utils.functional.__proxy__ object at 0x7f995c306f50>), 
(datetime.time(0, 15), <django.utils.functional.__proxy__ object at 0x7f995c310f50>), 
(datetime.time(0, 30), <django.utils.functional.__proxy__ object at 0x7f995c310bd0>), 
(datetime.time(0, 45), <django.utils.functional.__proxy__ object at 0x7f995c310ed0>), 
(datetime.time(1, 0), <django.utils.functional.__proxy__ object at 0x7f995c310fd0>)) 

正如你所看到的,datetime.time(0,0)已改为一个__proxy__对象(翻译字符串)。更重要的是,该代理的指针地址与此选项的label值相同。我在我的项目中使用了DjangoChoices,并且之前没有遇到过这个问题。有没有人看过类似的东西?

回答

0

事实证明,这已在更高版本中修复 - 将django-choices升级到最新版本。

的问题是一些代码,看起来像这样:

if not self.value: 
    self.value = self.label 

...和time(0,0)在这方面评估,以False

+1

该死的,即将回复:)无论如何,这里是修正的提交:https://github.com/bigjason/django-choices/commit/0b00f2e85db9376505503af3c3a75f0cd79e3ae7 – Djizeus

相关问题