本文整理汇总了Python中django.forms.Widget方法的典型用法代码示例。如果您正苦于以下问题:Python forms.Widget方法的具体用法?Python forms.Widget怎么用?Python forms.Widget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms
的用法示例。
在下文中一共展示了forms.Widget方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: formfield_for_dbfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Widget [as 别名]
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'widget_type':
widgets = widget_manager.get_widgets(self.request.GET.get('page_id', ''))
form_widget = WidgetTypeSelect(widgets)
return forms.ChoiceField(choices=[(w.widget_type, w.description) for w in widgets],
widget=form_widget, label=_('Widget Type'))
if 'page_id' in self.request.GET and db_field.name == 'page_id':
kwargs['widget'] = forms.HiddenInput
field = super(
UserWidgetAdmin, self).formfield_for_dbfield(db_field, **kwargs)
return field
示例2: obj_as_dict
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Widget [as 别名]
def obj_as_dict(o):
if isinstance(o, DeclarativeFieldsMetaclass):
o = FormSerializer(form=o).data
if isinstance(o, forms.Field):
o = FormFieldSerializer(field=o).data
if isinstance(o, forms.Widget):
o = FormWidgetSerializer(widget=o).data
if isinstance(o, (list, tuple)):
o = [obj_as_dict(x) for x in o]
if isinstance(o, Promise):
try:
o = force_unicode(o)
except:
# Item could be a lazy tuple or list
try:
o = [obj_as_dict(x) for x in o]
except:
raise Exception('Unable to resolve lazy object %s' % o)
if callable(o):
o = o()
if isinstance(o, dict):
for k, v in o.items():
o[k] = obj_as_dict(v)
return o
示例3: test_decimalfield_widget_attrs
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Widget [as 别名]
def test_decimalfield_widget_attrs(self):
f = DecimalField(max_digits=6, decimal_places=2)
self.assertEqual(f.widget_attrs(Widget()), {})
self.assertEqual(f.widget_attrs(NumberInput()), {'step': '0.01'})
f = DecimalField(max_digits=10, decimal_places=0)
self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1'})
f = DecimalField(max_digits=19, decimal_places=19)
self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1e-19'})
f = DecimalField(max_digits=20)
self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'})
f = DecimalField(max_digits=6, widget=NumberInput(attrs={'step': '0.01'}))
self.assertWidgetRendersTo(f, '<input step="0.01" name="f" type="number" id="id_f" required>')
示例4: test_format_value
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Widget [as 别名]
def test_format_value(self):
widget = Widget()
self.assertIsNone(widget.format_value(None))
self.assertIsNone(widget.format_value(''))
self.assertEqual(widget.format_value('español'), 'español')
self.assertEqual(widget.format_value(42.5), '42.5')
示例5: test_value_omitted_from_data
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import Widget [as 别名]
def test_value_omitted_from_data(self):
widget = Widget()
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False)