itemprop = "text">
I have a form that is never valid. This form is just three drop-down boxes when the form is presented, then the values of all the boxes are populated and the first is chosen, so there is no problem, the user can not present bad values, then Also form.is_valid () always returns false. help please!
form
CLUSTER_TYPES = (('' ST '', 'state'), ('cnt', 'county'), ('fcd') '), (' GCC ',' Circle Clustering '),); MAP_VIEWS = (('1', 'Single Map'), ('2', 'Two Maps'), ('4', 'Four Maps'),); Class ViewDataForm (forms.Form): def __init__ (auto, set = none, * args, ** kwargs): set = kwargs.pop ('data_sets') Super (ViewDataForm, itself) .__init__ (* args, * * Kwargs) Processed_sets = [] For DS in the set: processed_sets.append ((ds.id, ds.name)) self.fields ['data_sets'] = forms.ChoiceField (label = 'data set', option = processed_sets ) Self Field ['Clustering'] = Form. Chargefield (label = 'clustering', option = CLUSTER_TYPES) itself Field ['map_view'] = form Chargefield (label = 'map view', option = MAP_VEWS) view
def main_view (requested): # We set the data set for this user set Will receive a list of = DataSet.objects.filter (owner = request.user) # To populate the Geogenson string object potentially see Jason = '#' View the default map View map = MapPicture If the request type request.method == 'POST': form = see the data form (request .post, request.FILES, data_sets = .filter (state = 'Ohio', mapcount = 1) mapView = mapView [0] Set) v = Form.is_valid () if form.is_valid (): # data set DS = dataset Object .filter (id = int (form.cleaned_data ['data_set'])) DS = DS [0] # Get the county data point classification qs_county = DataPointClassification.objects.filter (dataset = DS, partition = form.cleaned_data [' Clustering ']) Create #Geogeson Object (a feature collection) json =' 'json + =' {"type": "Feature Collection", "FEATURES": [['index = 0: index' for the county in qs_county] ; 0: json + = ',' json + = '{"type": "feature", "geometry":' json + = county. Population GOOM_POLIEJOJOSON JASON + = ', "Properties": {"Aggradia": "' + Str (County.Egdata) + '"}' JASON + = '}' index + = 1 JASON + = ']}' MapView = Mapview.bizct Filters (state = 'Ohio', mapcount = 1) mapView = MV [0] Other: Form = ViewDataforms (data_set = set) # Feedback C = RequestContacts (Request, {'form': form, 'mapview_long': see map Center length, 'map view_litid': see map, centerpost, 'map view_jum level': MapView.zoomLevel, 'geojson': json, 'valid_was_it': v} Return render_to_response ('main.html', c)
The __ init has override signature __ method, so that the situational parameters set . However, when you instantiate it, you pass request.POST as the first codic logic - that's why the form never gets data, so it is not valid. Do not change the signature of __ init __ . In fact, you have everything set up properly so that you do not need it: Remove only sets = none from the definition of the method, and all this should be done.
Comments
Post a Comment