2015-10-23 34 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

相關問題