class MyField forms fields Field def __init__ self data_source None ar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class MyField(forms.fields.Field):
def __init__(self, data_source = None, *args, **kwargs):
super(AjaxDropDownField, self).__init__(*args, **kwargs)
if (data_source != None):
self._model = data_source
def get_data_source(self):
return self._model
def set_data_source(self, value):
self._model = value
data_source = property(get_data_source, set_data_source)
class MyForm(forms.ModelForm):
country = fields.MyField(label=_("Test"), required=True)
class Meta:
model = models.Test
def __init__(self, data = None, instance = None):
super(MyForm.self).__init__(data, instance=instance, auto_id="id_state_%s")
self.fields['country'].data_source = instance