Feature Attributes

5 views
Skip to first unread message

Alan Boudreault

unread,
Nov 29, 2010, 3:45:31 PM11/29/10
to olwidget
Hi,

I'm trying to make a simple editable map to add a collection of
points. I'm wondering if there is already something for the feature
attributes. In example, I'd like to have an attribute 'name' for all
my points. Perhaps a popup would be ok to edit that attribute. Can we
already do that with olwidget?

Alan

Charlie DeTar

unread,
Dec 1, 2010, 9:03:05 PM12/1/10
to olwi...@googlegroups.com

If you want to edit additional attributes besides the geometry (for
example, adding a 'name' to each point), that'd have to be in separate
parts of a form. For example, if your model was like:

class NamedPoint(models.Model):
name = models.CharField(max_length=15)
point = models.PointField()

then you'd have a form that has a field for 'name' and a map widget for
'point'. For example, using a ModelForm:

from olwidget.forms import MapModelForm

class MyForm(MapModelForm):
class Meta:
model = NamedPoint

Or do I misunderstand your question?

best,
Charlie

Alan Boudreault

unread,
Dec 2, 2010, 8:38:39 AM12/2/10
to olwidget
Hi Charlie,

This is currently what I have, which works perfectly. However, what I
would like to do is to have a form/Map that allows me to create
multiple NamedPoint instances at the same time. I think of a map that
I can add multiple points and a way to edit their attribute name
somehow.

Thanks,
Alan

Charlie DeTar

unread,
Dec 2, 2010, 9:11:47 AM12/2/10
to olwi...@googlegroups.com
On 12/02/2010 08:38 AM, Alan Boudreault wrote:
> Hi Charlie,
>
> This is currently what I have, which works perfectly. However, what I
> would like to do is to have a form/Map that allows me to create
> multiple NamedPoint instances at the same time. I think of a map that
> I can add multiple points and a way to edit their attribute name
> somehow.
>
> Thanks,
> Alan

Ah, I see. That's a bit more complicated. The way I would do that is
create a form that uses a collection of points, and then when you
process the form, create multiple models from that point, for example:

from olwidget.widgets import EditableMap

class Form(forms.Form):
points = forms.CharField(widget=EditableMap({
'geometry': 'point',
'is_collection': True,
}))

.. in the view:

if form.is_valid():
multipoint = form.cleaned_data['points']
for point in multipoint:
... do something ...

This doesn't let you have a different other value (e.g. "name") for each
point though.

-charlie

Alan Boudreault

unread,
Dec 2, 2010, 9:38:07 AM12/2/10
to olwi...@googlegroups.com, Charlie DeTar
All right,

That's what I thought. I'm going to create a template manually for this page.

thanks Charlie!
Alan

Reply all
Reply to author
Forward
0 new messages