-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass properties to the geojsonfeature filter #15
Comments
I ended up using an inherited generic views, redefining the get_queryset method to return the desired queryset. |
Hi ! It looks like you're confused between the view (serving GeoJSON) and the template filter (embedding GeoJSON within an HTML template). So, if you need to serve GeoJSON with some properties, just add this in
But if you need to embed some GeoJSON within an HTML page (less common to be honest), you may be right, the many parameters are maybe useless ! I will open another issue for that :) |
Hi, no I am not confused :) I exactly did what you suggested in urls. |
This is the code I used: views.py
urls.py
|
Ok, great, indeed a filtered queryset like this should work. Regarding the other question: so far it looks like the template filter |
because according to this: we may pass the following parameters to the filter: def geojsonfeature(source, geometry_field='geom', properties=None, srid=GEOJSON_DEFAULT_SRID) but cannot figure out how to pass the properties and srid parameters (it looks like a Django filter will accept just one parameter from template). |
Yes indeed, this part of the code was written in a way that cannot be used :D (purpose of issue #16) We could specify only one parameter as string (split on
|
+1, thanks :) |
Hi, I cannot figure out how to pass the properties parameter to the geojsonfeature filter.
With GeoJSONLayerView in urls.py this is easy:
But for my use case I need to filter the model, that's why I have created a view like this:
def mymodel_geojson(request):
object_list = MyModel.objects.all().filter(some_filter_here)
properties= ['field1', 'field2',]
return render_to_response(
'myapp/mytemplate.geojson',
{
'object_list': object_list,
'properties': properties,
}, )
Now in my template, how do I pass the parameters?
{% load geojson_tags %}
{{ object_list|geojsonfeature:"???" }}
According to this it should not be possible to create a filter accepting multiple parameters:
http://stackoverflow.com/questions/420703/how-do-i-add-multiple-arguments-to-my-custom-template-filter-in-a-django-templat
thanks for the great library!
The text was updated successfully, but these errors were encountered: