Closed askpatrickw closed 5 years ago
@askpatrickw probably you have been solved it, but if it can be useful for someone, it should work passing the list of properties to be rendered, I mean:
url(r'^data/$', GeoJSONLayerView.as_view(
model=Water,
properties=['popupContent', 'anotherField', ...]
), name='data'),
Hi @XaviTorello, I see in your example you use "anotherField" as an additional example. My issue is with Methods that have the @property
decorator, not a model field.
Have you tested this with a model method decorated with @property
?
As in the docs: https://docs.djangoproject.com/en/2.1/topics/db/models/#model-method
Yes, I've it working in some projects. Did you have the chance to test it with a recent version?
Something like:
urls.py
urlpatterns = [
...
url(r'^data/location$',
GeoJSONLayerView.as_view(
model=models.Location,
properties=['name', 'html']
),
name='location-data',
),
...
]
models.py
class Location(models.Model):
...
@property
def html(self):
return '<h1>{}</h1><p><{}</p>'.format(
self.name,
self.description
)
will return:
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{
"name":"Coll d'Ordino",
"html":"<h1>Coll d'Ordino</h1><p><Lorem ipsum...</p>",
"model":"api.location"
},
"id":1,
"geometry":{
"type":"Point",
"coordinates":[
1.5722207,
42.5549682
]
}
}
....
]
}
I'm not actively using this any longer so I'm going to close this as I won't be able to assist and the original issue was reported 3 years ago.
I have a @property defined on my Model that works fine in django shell, but when I attempt to use it with GeoJSONLayerView it does not come through in the data.
models.py
Works fine in Shell
In urls.py I have specified the property
but in my data its not coming through, only the geometry is. If I specify a field like 'name' in properties then those field values work.
Maybe this Is this a regression of #31
Thanks