Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aamalev/serializers
https://github.com/aamalev/serializers
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aamalev/serializers
- Owner: aamalev
- License: lgpl-3.0
- Created: 2013-08-30T11:32:36.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-10-28T14:06:56.000Z (about 11 years ago)
- Last Synced: 2023-03-12T06:34:35.697Z (almost 2 years ago)
- Language: Python
- Homepage:
- Size: 156 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
serializers
===========
Django compatible serializersCursorJSON
-----------
Serialize data without model###Registered
```
from django.core import serializers
serializers.register_serializer('cursorjson','serializers.cursorjson')
```###Uses
Example serialize data from PostGIS
```
...
response = HttpResponse(content_type='application/json')
cursor = connections['osm'].cursor()
cursor.execute("SELECT id, name, ST_AsGeoJSON(ST_Transform(geom,4326)) AS geom FROM osm")
serializers.serialize('cursorjson', cursor, json=['geom'], stream=response)
...
```###Params
json - list of fields which contains json objectprimary - name for primary key (default "id"). If primary=None returns array of objects. If primary="id" then object {id:object,id:object..}
FeatureCollection
-------------
Serialize geofields from GeoQuerySet, list, tuple..###Registered
```
from django.core import serializers
serializers.register_serializer('geojson','serializers.featurecollection')
```
or in settings.py:
```
SERIALIZATION_MODULES = { 'geojson' : 'serializers.featurecollection' }
```###Uses
Example serialize data from geomodel
```
...
response = HttpResponse(content_type='application/json')
serializers.serialize('geojson', City.objects.all(), fields=['point','poly'], stream=response)
...
```###Params
fields - list of geometry fields (for serialize geometry only)geometry - geometry field into feature
geometry_collection - list of geometry fields (multigeometry for feature)
properties - list of fields (properties for feature)