@@ -94,17 +94,16 @@ def to_representation(self, instance):
94
94
"""
95
95
# prepare OrderedDict geojson structure
96
96
feature = OrderedDict ()
97
- # the list of fields that will be processed by get_properties
98
- # we will remove fields that have been already processed
99
- # to increase performance on large numbers
100
- fields = list (self .fields .values ())
97
+
98
+ # keep track of the fields being processed
99
+ processed_fields = set ()
101
100
102
101
# optional id attribute
103
102
if self .Meta .id_field :
104
103
field = self .fields [self .Meta .id_field ]
105
104
value = field .get_attribute (instance )
106
105
feature ["id" ] = field .to_representation (value )
107
- fields . remove ( field )
106
+ processed_fields . add ( self . Meta . id_field )
108
107
109
108
# required type attribute
110
109
# must be "Feature" according to GeoJSON spec
@@ -115,7 +114,8 @@ def to_representation(self, instance):
115
114
field = self .fields [self .Meta .geo_field ]
116
115
geo_value = field .get_attribute (instance )
117
116
feature ["geometry" ] = field .to_representation (geo_value )
118
- fields .remove (field )
117
+ processed_fields .add (self .Meta .geo_field )
118
+
119
119
# Bounding Box
120
120
# if auto_bbox feature is enabled
121
121
# bbox will be determined automatically automatically
@@ -126,7 +126,15 @@ def to_representation(self, instance):
126
126
field = self .fields [self .Meta .bbox_geo_field ]
127
127
value = field .get_attribute (instance )
128
128
feature ["bbox" ] = value .extent if hasattr (value , 'extent' ) else None
129
- fields .remove (field )
129
+ processed_fields .add (self .Meta .bbox_geo_field )
130
+
131
+ # the list of fields that will be processed by get_properties
132
+ # we will remove fields that have been already processed
133
+ # to increase performance on large numbers
134
+ fields = [
135
+ field_value for field_key , field_value in self .fields .items ()
136
+ if field_key not in processed_fields
137
+ ]
130
138
131
139
# GeoJSON properties
132
140
feature ["properties" ] = self .get_properties (instance , fields )
0 commit comments