Commits

Dmitri Lebedev committed 635a9de

wrote a lookup for foreign keys

Comments (0)

Files changed (1)

vectorformats/Formats/Django.py

             
             if self.properties:   
                 for p in self.properties:
-                    feature.properties[p] = getattr(res, p)
+                    if '__' in p:  # looking up in a chain of related fields. Does not support aggregation or method calling.
+                        current = res
+                        for field_name in p.split('__'):
+                            current = getattr(current, field_name, None)
+                            if current is None:
+                                continue
+                        feature.properties[p] = current
+                    else:
+                        feature.properties[p] = getattr(res, p)
             results.append(feature) 
         return results