Skip to content Skip to sidebar Skip to footer

Validating A Form With Overloaded _init_

I have a form with a new init method, which allow to display various choices according to a parameter : class Isochrone_Set_Parameters(forms.Form): Grid_Choices = Grids_Selecti

Solution 1:

You've changed the signature to the form initialization, so that the first parameters is now Grid_Type rather than the usual data. This means that when you do form = Isochrone_Set_Parameters(request.POST), the POST is being used for Grid_Type.

Either make sure you always pass Grid_Type, or (preferably) don't put that in the parameter list at all: get it from kwargs:

def__init__(self, *args, **kwargs):
    Grid_Type = kwargs.pop('Grid_Type', None)
    super(Isochrone_Set_Parameters, self).__init__(*args, **kwargs)
    ...

(Also, please use PEP8-standard naming conventions: IsochroneSetParameters, grid_type, etc).

Post a Comment for "Validating A Form With Overloaded _init_"