django-geojson icon indicating copy to clipboard operation
django-geojson copied to clipboard

Problem serializing a model class with a foreign field

Open jorgeas80 opened this issue 10 years ago • 2 comments

Hello,

I'm struggling with a problem using this plugin, serializing to GeoJSON a simple model class (call it A) with a Polygon.

The problem is another model class (call it B) contains a foreign key to A, and the serializer throws an error, because it tries to find one of the B fields in A. Of course, it isn't found.

May it be a bug on the serializer?

Extended information about the problem here

jorgeas80 avatar Apr 08 '14 13:04 jorgeas80

It looks like a bug indeed. You can try (temporarly) to specify explicitly the list of properties fields.

leplatrem avatar Apr 08 '14 14:04 leplatrem

Thanks for your response. I finally could solve it by preventing Django to create backwards relation between ROI and Series.

class Series(gismodels.Model): # Prevents django to create a backwards relation between ROI and Series roi = models.ForeignKey(ROI, related_name='+') indicator = models.ForeignKey(Indicator)

I hope it helps.

jorgeas80 avatar Apr 08 '14 18:04 jorgeas80