Comments (12)
Can you use a SerializerMethodField for the data from HStore?
from django-rest-framework-gis.
I don't think so: it would be an extra field in your serializer class, which would return the following "properties" dict:
"properties": {
"extra_field": {
"metadata1": value1,
}
}
And what I would like as result:
"properties": {
"metadata1": value1
}
from django-rest-framework-gis.
In your GeoFeatureModelSerializer put
metadata1 = SerializerMethodField()
def get_metadata1(self, obj):
....
return value1
This will make metadata1
entry and add it to properties
after geo serializer is done.
from django-rest-framework-gis.
Yes but that's not what I want. I don't want the extra_field to be visible. The GeoJSON properties dict should solely be filled with data from the HStore field, not from the fields declared in the serializer.
from django-rest-framework-gis.
You can make a serializer field for each value you want included, and explicitly list them in Meta.fields
.
from django-rest-framework-gis.
Well, that would not work with my variable metadata requirement (also the reason I'm using HStore).
from django-rest-framework-gis.
I see, makes sense.
from django-rest-framework-gis.
But still could've had this:
class MySerializer(GeoFeatureModelSerializer):
metafield = SerializerMethodField()
def get_metafield(self, obj):
return meta_value
def to_representation(self, instance):
res = super(MySerializer, self).to_representation(instance)
res['properties'] = res['properties']['metafield']
return res
# similar for to_internal_value
from django-rest-framework-gis.
Left a few comments on #71
from django-rest-framework-gis.
Thank you @sh4wn, I merged #71 manually in 5a82a00.
I needed to change a few bits in order to avoid losing some performance gains I managed to introduce in the latest versions, but the behaviour you introduced should be unchanged (except for the name of the method get_feature_properties which I renamed to get_properties for simplicity).
Please test 0.9.5 alpha in your app and report any feedback.
from django-rest-framework-gis.
Cool, thanks! I'll check it next week.
from django-rest-framework-gis.
0.9.5 was released a few weeks ago, I'm considering this solved.
from django-rest-framework-gis.
Related Issues (20)
- How Deserialize data from geojson format HOT 2
- [CI] Move drf-gis to Github actions HOT 4
- Openapi schema generation does not support serializers not subclassing GeoFeatureModelSerializer HOT 9
- GEOS_ERROR when using empty Point in GeometryField
- Serializing to RasterField() HOT 5
- [bug] Browsable API form does not prepopulates the form with model data
- [deps] Add support for Django 3.2 and Django 4.0 HOT 2
- OpenAPI schema generation fails if the GeometryField is not in the model HOT 1
- Comcriptiment
- [bug] id_field is not deserialized HOT 2
- Django 3.2.13 warning message HOT 1
- Using GeoFeatureModelSerializer with files
- GeoFeatureModelSerializer and QueryFieldsMixin
- Idea of support for RawQuery using the classical class based flow of Django and DRF HOT 1
- Use GeoFeatureModelSerializer without geometry HOT 7
- Bug: This plugin is changing coordinates when creating new model instances.
- TypeError: Cannot set GeoPoint SpatialProxy (POINT) with value of type: <class 'dict'> HOT 4
- Using the BBOX filter creates invalid Open API Schema
- Aberations and enclave when using precision arguments on geometry field HOT 2
- Release or roadmap HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-rest-framework-gis.