我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用django.forms.Widget()。
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
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
def __init__(self, **fields): """Given a dict of fields with action lists, prepare the JSON.""" self.rules = [] for field, actions in fields.items(): self.rules.append(Rule(field, actions)) super(Field, self).__init__( required=False, widget=Widget(self), )
def __init__(self, field): """Take the field which has the rules to render.""" super(Widget, self).__init__() self.field = field