Ticket #18470: forms.py

File forms.py, 731 bytes (added by jnschaeffer@…, 12 years ago)

Pair of example fields, one using a class-based widget and one using an object-based widget

Line 
1from django import forms
2
3class FieldWithClassWidget(forms.Field):
4
5 def __init__(self,*args,**kwargs):
6 super(FieldWithClassWidget,self).__init__(*args,**kwargs)
7
8 # Accept other required kwargs...
9
10 self.widget = kwargs['widget'] if 'widget' in kwargs else forms.Textarea
11
12class FieldWithObjectWidget(forms.Field):
13
14 def __init__(self,*args,**kwargs):
15 super(FieldWithObjectWidget,self).__init__(*args,**kwargs)
16
17 # Accept other required kwargs...
18
19 self.widget = kwargs['widget'] if 'widget' in kwargs else forms.Textarea()
20
21class FormWithClassWidget(forms.Form):
22
23 field = FieldWithClassWidget()
24
25class FormWithObjectWidget(forms.Form):
26
27 field = FieldWithObjectWidget()
Back to Top