[Gfoss] geodjango inserire campo geom da form

Paolo Corti pcorti a gmail.com
Ven 26 Nov 2010 11:51:28 CET

Caro Luca
come spiegato BENE ;) sulla documentazione di Django [1] (leggi la nota):

"If you specify fields or exclude when creating a form with ModelForm,
then the fields that are not in the resulting form will not be set by
the form's save() method. Django will prevent any attempt to save an
incomplete model, so if the model does not allow the missing fields to
be empty, and does not provide a default value for the missing fields,
any attempt to save() a ModelForm with missing fields will fail. To
avoid this failure, you must instantiate your model with initial
values for the missing, but required fields..."

pertanto puoi usare uno dei due modi suggeriti, ad es modificando
cosi' la tua view, vedrai che ti funziona:

if form.is_valid():
            pnt =
            pnt.srid = 4326
            place = form.save(commit=False)
            place.geom = pnt

[1] http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form


Paolo Corti
GIS specialist and web developer
web: http://www.paolocorti.net
twitter: @paolo_corti

Maggiori informazioni sulla lista Gfoss