@@ -44,10 +44,18 @@ def __init__(self, converters=None):
4444 self .converters = converters
4545
4646 def convert (self , model , field , field_args ):
47+ validators = []
48+ try :
49+ if hasattr (field , 'validators' ) and \
50+ field .validators is not None :
51+ validators = field .validators
52+ except :
53+ pass
54+
4755 kwargs = {
4856 'label' : getattr (field , 'verbose_name' , field .name ),
4957 'description' : field .help_text or '' ,
50- 'validators' : [] if not field . validators else field . validators ,
58+ 'validators' : validators ,
5159 'filters' : [] if not field .filters else field .filters ,
5260 'default' : field .default ,
5361 }
@@ -82,8 +90,8 @@ def convert(self, model, field, field_args):
8290 def _string_common (cls , model , field , kwargs ):
8391 if field .max_length or field .min_length :
8492 kwargs ['validators' ].append (
85- validators .Length (max = field .max_length or - 1 ,
86- min = field .min_length or - 1 ))
93+ validators .Length (max = field .max_length or - 1 ,
94+ min = field .min_length or - 1 ))
8795
8896 @classmethod
8997 def _number_common (cls , model , field , kwargs ):
@@ -141,7 +149,7 @@ def conv_DateTime(self, model, field, kwargs):
141149
142150 @converts ('BinaryField' )
143151 def conv_Binary (self , model , field , kwargs ):
144- #TODO: may be set file field that will save file`s data to MongoDB
152+ # TODO: may be set file field that will save file`s data to MongoDB
145153 if field .max_bytes :
146154 kwargs ['validators' ].append (validators .Length (max = field .max_bytes ))
147155 return BinaryField (** kwargs )
@@ -169,12 +177,12 @@ def conv_List(self, model, field, kwargs):
169177
170178 @converts ('SortedListField' )
171179 def conv_SortedList (self , model , field , kwargs ):
172- #TODO: sort functionality, may be need sortable widget
180+ # TODO: sort functionality, may be need sortable widget
173181 return self .conv_List (model , field , kwargs )
174182
175183 @converts ('GeoLocationField' )
176184 def conv_GeoLocation (self , model , field , kwargs ):
177- #TODO: create geo field and widget (also GoogleMaps)
185+ # TODO: create geo field and widget (also GoogleMaps)
178186 return
179187
180188 @converts ('ObjectIdField' )
0 commit comments