當前位置: 首頁>>代碼示例>>Python>>正文


Python DecimalField.has_changed方法代碼示例

本文整理匯總了Python中django.forms.DecimalField.has_changed方法的典型用法代碼示例。如果您正苦於以下問題:Python DecimalField.has_changed方法的具體用法?Python DecimalField.has_changed怎麽用?Python DecimalField.has_changed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms.DecimalField的用法示例。


在下文中一共展示了DecimalField.has_changed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_decimalfield_changed

# 需要導入模塊: from django.forms import DecimalField [as 別名]
# 或者: from django.forms.DecimalField import has_changed [as 別名]
    def test_decimalfield_changed(self):
        f = DecimalField(max_digits=2, decimal_places=2)
        d = decimal.Decimal("0.1")
        self.assertFalse(f.has_changed(d, '0.10'))
        self.assertTrue(f.has_changed(d, '0.101'))

        with translation.override('fr'), self.settings(USE_L10N=True):
            f = DecimalField(max_digits=2, decimal_places=2, localize=True)
            localized_d = formats.localize_input(d)  # -> '0,1' in French
            self.assertFalse(f.has_changed(d, localized_d))
開發者ID:2015E8007361074,項目名稱:django,代碼行數:12,代碼來源:test_decimalfield.py

示例2: __init__

# 需要導入模塊: from django.forms import DecimalField [as 別名]
# 或者: from django.forms.DecimalField import has_changed [as 別名]
    def __init__(self, currency_widget=None, currency_choices=CURRENCY_CHOICES,
                 choices=CURRENCY_CHOICES, max_value=None, min_value=None,
                 max_digits=None, decimal_places=None, *args, **kwargs):

        # choices does not make sense in this context, it would mean we had
        # to replace two widgets with one widget dynamically... which is a
        # mess. Instead, we let currency_choices be the same as choices and
        # raise a warning.
        if currency_choices != CURRENCY_CHOICES:
            warn('currency_choices will be deprecated in favor of choices', PendingDeprecationWarning)
            choices = currency_choices

        amount_field = DecimalField(max_value, min_value, max_digits, decimal_places, *args, **kwargs)
        currency_field = ChoiceField(choices=choices)

        if VERSION < (1, 10) and hasattr(amount_field, '_has_changed') and hasattr(currency_field, '_has_changed'):
            amount_field.has_changed = amount_field._has_changed
            currency_field.has_changed = currency_field._has_changed

        # TODO: No idea what currency_widget is supposed to do since it doesn't
        # even receive currency choices as input. Somehow it's supposed to be
        # instantiated from outside. Hard to tell.
        if currency_widget:
            self.widget = currency_widget
        else:
            self.widget = MoneyWidget(
                amount_widget=amount_field.widget,
                currency_widget=currency_field.widget
            )

        # The two fields that this widget comprises
        fields = (amount_field, currency_field)
        super(MoneyField, self).__init__(fields, *args, **kwargs)
開發者ID:Suitcake,項目名稱:django-money,代碼行數:35,代碼來源:fields.py


注:本文中的django.forms.DecimalField.has_changed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。