Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
c5517b9e
Kaydet (Commit)
c5517b9e
authored
Şub 23, 2016
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26266 -- Output the primary key in the GeoJSON serializer properties
Thanks Tim Graham for the review.
üst
6637cd0e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
0 deletions
+18
-0
geojson.py
django/contrib/gis/serializers/geojson.py
+3
-0
serializers.txt
docs/ref/contrib/gis/serializers.txt
+8
-0
1.10.txt
docs/releases/1.10.txt
+4
-0
test_serializers.py
tests/gis_tests/geoapp/test_serializers.py
+3
-0
No files found.
django/contrib/gis/serializers/geojson.py
Dosyayı görüntüle @
c5517b9e
...
...
@@ -47,6 +47,9 @@ class Serializer(JSONSerializer):
"type"
:
"Feature"
,
"properties"
:
self
.
_current
,
}
if
((
self
.
selected_fields
is
None
or
'pk'
in
self
.
selected_fields
)
and
'pk'
not
in
data
[
"properties"
]):
data
[
"properties"
][
"pk"
]
=
obj
.
_meta
.
pk
.
value_to_string
(
obj
)
if
self
.
_geometry
:
if
self
.
_geometry
.
srid
!=
self
.
srid
:
# If needed, transform the geometry in the srid of the global geojson srid
...
...
docs/ref/contrib/gis/serializers.txt
Dosyayı görüntüle @
c5517b9e
...
...
@@ -71,3 +71,11 @@ Would output::
}
]
}
When the ``fields`` parameter is not specified, the ``geojson`` serializer adds
a ``pk`` key to the ``properties`` dictionary with the primary key of the
object as the value.
.. versionchanged:: 1.10
The ``pk`` key was added to the ``properties`` dictionary.
docs/releases/1.10.txt
Dosyayı görüntüle @
c5517b9e
...
...
@@ -131,6 +131,10 @@ Minor features
:attr:`MultiLineString.closed
<django.contrib.gis.geos.MultiLineString.closed>` properties.
* The :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` now outputs the
primary key of objects in the ``properties`` dictionary if specific fields
aren't specified.
:mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/gis_tests/geoapp/test_serializers.py
Dosyayı görüntüle @
c5517b9e
...
...
@@ -33,6 +33,8 @@ class GeoJSONSerializerTests(TestCase):
self
.
assertEqual
(
len
(
geodata
[
'features'
]),
len
(
City
.
objects
.
all
()))
self
.
assertEqual
(
geodata
[
'features'
][
0
][
'geometry'
][
'type'
],
'Point'
)
self
.
assertEqual
(
geodata
[
'features'
][
0
][
'properties'
][
'name'
],
'Chicago'
)
first_city
=
City
.
objects
.
all
()
.
order_by
(
'name'
)
.
first
()
self
.
assertEqual
(
geodata
[
'features'
][
0
][
'properties'
][
'pk'
],
str
(
first_city
.
pk
))
def
test_geometry_field_option
(
self
):
"""
...
...
@@ -76,6 +78,7 @@ class GeoJSONSerializerTests(TestCase):
geodata
=
json
.
loads
(
geojson
)
self
.
assertIn
(
'county'
,
geodata
[
'features'
][
0
][
'properties'
])
self
.
assertNotIn
(
'founded'
,
geodata
[
'features'
][
0
][
'properties'
])
self
.
assertNotIn
(
'pk'
,
geodata
[
'features'
][
0
][
'properties'
])
def
test_srid_option
(
self
):
geojson
=
serializers
.
serialize
(
'geojson'
,
City
.
objects
.
all
()
.
order_by
(
'name'
),
srid
=
2847
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment