本文整理汇总了Python中fields.Field类的典型用法代码示例。如果您正苦于以下问题:Python Field类的具体用法?Python Field怎么用?Python Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Field类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(
self,
queryset,
empty_label=u"---------",
cache_choices=False,
required=True,
widget=None,
label=None,
initial=None,
help_text=None,
to_field_name=None,
*args,
**kwargs
):
if required and (initial is not None):
self.empty_label = None
else:
self.empty_label = empty_label
self.cache_choices = cache_choices
# Call Field instead of ChoiceField __init__() because we don't need
# ChoiceField.__init__().
Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs)
self.queryset = queryset
self.choice_cache = None
self.to_field_name = to_field_name
示例2: __init__
def __init__(self):
Field.__init__(self)
scriptList.register(self)
from kivy.app import App
def inner(*args):
self.stack = App.get_running_app().root.ids['deck'].ids['stack']
from kivy.clock import Clock
Clock.schedule_once(inner,1)
示例3: clean
def clean(self, value):
Field.clean(self, value)
if value in EMPTY_VALUES:
return None
try:
value = self.queryset.get(pk=value)
except self.queryset.model.DoesNotExist:
raise ValidationError(self.error_messages['invalid_choice'])
return value
示例4: clean
def clean(self, value):
Field.clean(self, value)
if value in ('', None):
return None
try:
value = self.queryset.model._default_manager.get(pk=value)
except self.queryset.model.DoesNotExist:
raise ValidationError(gettext(u'Select a valid choice. That choice is not one of the available choices.'))
return value
示例5: __init__
def __init__(self, queryset, empty_label=u"---------", cache_choices=False,
required=True, widget=Select, label=None, initial=None, help_text=None):
self.queryset = queryset
self.empty_label = empty_label
self.cache_choices = cache_choices
# Call Field instead of ChoiceField __init__() because we don't need
# ChoiceField.__init__().
Field.__init__(self, required, widget, label, initial, help_text)
self.widget.choices = self.choices
示例6: clean
def clean(self, value):
Field.clean(self, value)
if value in EMPTY_VALUES:
return None
if self.to_field_name:
value = deepcopy(self.queryset).filter(self.to_field_name + ' =',
value).get()
else:
value = self.queryset.model.get(value)
if not value:
raise ValidationError(self.error_messages['invalid_choice'])
return value
示例7: validate
def validate(self, value):
return Field.validate(self, value)
示例8: parse_field
def parse_field(name):
if isinstance(name, Field) or isinstance(name, FieldSize):
size = name
else:
size = Field.find(name)
return size
示例9: test_inverse
def test_inverse(self):
a = Field(7, 23)
self.assertEqual(a.inverse().value, 10)
self.assertEqual((a.inverse() * 7).value, 1)