Coder Social home page Coder Social logo

Comments (12)

pglotov avatar pglotov commented on July 27, 2024

Can you use a SerializerMethodField for the data from HStore?

from django-rest-framework-gis.

lrvdijk avatar lrvdijk commented on July 27, 2024

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.

pglotov avatar pglotov commented on July 27, 2024

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.

lrvdijk avatar lrvdijk commented on July 27, 2024

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.

pglotov avatar pglotov commented on July 27, 2024

You can make a serializer field for each value you want included, and explicitly list them in Meta.fields.

from django-rest-framework-gis.

lrvdijk avatar lrvdijk commented on July 27, 2024

Well, that would not work with my variable metadata requirement (also the reason I'm using HStore).

from django-rest-framework-gis.

pglotov avatar pglotov commented on July 27, 2024

I see, makes sense.

from django-rest-framework-gis.

pglotov avatar pglotov commented on July 27, 2024

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.

nemesifier avatar nemesifier commented on July 27, 2024

Left a few comments on #71

from django-rest-framework-gis.

nemesifier avatar nemesifier commented on July 27, 2024

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.

lrvdijk avatar lrvdijk commented on July 27, 2024

Cool, thanks! I'll check it next week.

from django-rest-framework-gis.

nemesifier avatar nemesifier commented on July 27, 2024

0.9.5 was released a few weeks ago, I'm considering this solved.

from django-rest-framework-gis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.