I have a problem with Django 1.5.4. I put the question in StackOverflow instead ofhttp://gis.stackexchange.com/ because I'm almost 100% sure is not a GIS related problem.
Here is my set up:
My models.py
from django.contrib.auth.models import User from django.contrib.gis.db import models as gismodels # This models a region of interest, using a polygon class ROI(gismodels.Model): label = models.CharField(max_length=256, default='ROI') area = models.FloatField(default=0.0) geom = gismodels.PolygonField(srid=4326) when = models.DateTimeField(default=datetime.now()) user = models.ForeignKey(User, null=True) objects = gismodels.GeoManager() def __unicode__(self): return unicode(self.label) class Meta: ordering = ['when'] class Indicator(models.Model): name = models.TextField() color = models.TextField() measurement_units = models.CharField(max_length=100) algorithm = models.CharField(max_length=256) data_origin = models.TextField() class Series(models.Model): roi = models.ForeignKey(ROI) indicator = models.ForeignKey(Indicator)As you can see, Series model contains a reference to ROI model
My settings.py
SERIALIZATION_MODULES = { 'geojson': 'djgeojson.serializers' }I'm using django-geojson to serialize my ROI objects into GeoJSON. I want to use this serializer to send a GeoJSON to my clients. So, my views.py looks like this
My views.py
@login_required def get_rois(request): rois_query = ROI.objects.filter(user=request.user) polygons = json.loads(serializers.serialize('geojson', rois_query)) return HttpResponse(json.dumps(polygons), mimetype='application/json')The problem: I'm getting this error in serialize call
AttributeError: 'ROI' object has no attribute 'roi'The relevant part of the error stack is this
File "/home/vagrant/.virtualenvs/myapp/local/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 122, in serialize s.serialize(queryset, **options) File "/home/vagrant/.virtualenvs/myapp/local/lib/python2.7/site-packages/djgeojson/serializers.py", line 349, in serialize self.serialize_queryset(queryset) File "/home/vagrant/.virtualenvs/myapp/local/lib/python2.7/site-packages/djgeojson/serializers.py", line 321, in serialize_queryset self.handle_reverse_field(obj, field, field_name) File "/home/vagrant/.virtualenvs/myapp/local/lib/python2.7/site-packages/djgeojson/serializers.py", line 243, in handle_reverse_field values = [reverse_value(related) for related in getattr(obj, field_name).iterator()]Looking at the stack, looks like there's a problem resolving the reverse reference of ROI to Series. Series has a roi field pointing to ROI, and I think the serializer thinks the roi field belongs to ROI class (incorrect) instead of to Series (correct). The expression infinite loop comes to my mind.
Besides, if I delete the roi field from Series model class, it works
I'm not sure about if it's a bug of django-geojson plugin (using the last version) or something wrong with my code (most likely). I've tried with the default json serializer, and still getting the same error. And also tried to inherit all model classes from gismodels instead of models. No effect.
Any clues?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d0a7a029-c1c6-4b1d-8901-90efde84e72e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment