makinacorpus / django-geojson

django-geojson is a collection of helpers to (de)serialize (Geo)Django objects into GeoJSON.
GNU Lesser General Public License v3.0
258 stars 69 forks source link

'Serializer' object has no attribute 'deserialize' #87

Open easherma opened 7 years ago

easherma commented 7 years ago

Thanks for this project. I'm playing around with importing it in the django shell to see how deserialization works on my data.

However, I get 'Serializer' object has no attribute 'deserialize' if I try to import

>>> from djgeojson.serializers import Serializer as GeoJSONSerializer
>>> GeoJSONSerializer().deserialize()

Does this method not exist if I'm running from shell? The documentation is unclear to me.

Gagaro commented 7 years ago

The documentation looks wrong. And i'm not sure the Deserializer is really tested because it looks like there is an exception which is not imported..

From looking through the tests, I'd say that you would need to do something like:

>>> from django.core import serializers
>>> serializers.deserialize('geojson', your_geojson)

Can you tell me if this works? Thanks.

hughstimson commented 6 years ago

I ran into the same error as @easherma when trying to de-serialize some GeoJSON that was returned from a geocoder API.

I tried @Gagaro's suggestion but it resulted in a different error:

{SerializerDoesNotExist}'geojson is a serialization-only serializer'

That's a pity. So far as I can tell there's no other library that will attempt to nicely convert some valid GeoJSON into a spatially aware Django model. Luckily I'm working with points so it's pretty easy to just parse them out from the JSON. But such a thing could be useful for more complex feature collections.

Gagaro commented 6 years ago

The thing is we do have a deserializer in the tests: https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/tests.py#L69-L131

We also have a Deserializer method, maybe you could try that one: https://github.com/makinacorpus/django-geojson/blob/master/djgeojson/serializers.py#L479-L521

I'm not sure what's up with all this.

marco-silva0000 commented 6 years ago

I haven't been able to use the Deserializer class. Will keep trying though.

This part of the documentation is wrong, https://django-geojson.readthedocs.io/en/latest/advanced.html#low-level-deserializer

probably outdated right?

andybak commented 4 years ago

Would be nice to at least fix the docs. This was my first experience of using the whole makinacorpus Geodjango stack and it didn't inspire immediate confidence!

erwinfeser commented 4 years ago

It seems to be that was never implemented