cannot import name ModelSerializerOptions

1,061 views
Skip to first unread message

Lei Du

unread,
Dec 4, 2014, 12:17:55 PM12/4/14
to django-rest-...@googlegroups.com
Hi everyone,

I'm trying to use the GeoFeatureModelSerializer for a rest API I'm writing. I'm getting this error when I hit my webpage (the full traceback is at the bottom): "cannot import name ModelSerializerOptions"

This is my serializer.py file, which I use to create my views:
```
from rest_framework import serializers
import models
from rest_framework_gis import serializers as gis_serializers

class LinkSerializer(gis_serializers.GeoFeatureModelSerializer):
    class Meta:
        model = models.Link
        geo_field = "geom"
        fields = ('id', )

class LinkFlowSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.LinkFlow
        fields = ('link_id', 'flow', 'flow_type')
```
The error is being thrown in the serializer.py file in the django-rest-frame-work-gis project on this line:
from rest_framework.serializers import ModelSerializer, ModelSerializerOptions 

My Investigation
---
I've looked through the django-rest-framework code, and I can't find a definition for ModelSerializerOptions class in serializers.py or any of the other files.

I was hoping for some suggestions on what to look into next.

Thanks,
Lei

Configuration
---
OS
Ubuntu 14.04

$ python -V
Python 2.7.6


$ pip show djangorestframework

Name: djangorestframework
Version: 2.4.3
Location: /usr/local/lib/python2.7/dist-packages
Requires:

$ pip show djangorestframework-gis

Name: djangorestframework-gis
Version: 0.7
Location: /usr/local/lib/python2.7/dist-packages
Requires: djangorestframework

Traceback
---
Environment:


Request Method: GET

Django Version: 1.7
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'rest_framework_gis',
 'phidata',
 'client')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  98.                 resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  338.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  367.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  361.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/lei/traffic/phi-estimation/visualization/visualization/urls.py" in <module>
  3. from phidata import views as phi_views
File "/home/lei/traffic/phi-estimation/visualization/phidata/views.py" in <module>
  4. from serializers import LinkSerializer, LinkFlowSerializer
File "/home/lei/traffic/phi-estimation/visualization/phidata/serializers.py" in <module>
  3. from rest_framework_gis import serializers as gis_serializers
File "/usr/local/lib/python2.7/dist-packages/rest_framework_gis/serializers.py" in <module>
  4. from rest_framework.serializers import ModelSerializer, ModelSerializerOptions

Exception Type: ImportError at /phidata/links/
Exception Value: cannot import name ModelSerializerOptions
error .html

Douglas Meehan

unread,
Dec 4, 2014, 12:24:42 PM12/4/14
to django-rest-...@googlegroups.com
DRF-GIS is not yet compatible with DRF 3.0. If you want to use it you'll have to use DRF 2.x for the time being.


> On Dec 4, 2014, at 12:17 PM, Lei Du <ion...@gmail.com> wrote:
>
> This message cannot be displayed because of the way it is formatted. Ask the sender to send it again using a different format or email program. text/html
> <error .html>

Lei Du

unread,
Dec 4, 2014, 1:52:08 PM12/4/14
to django-rest-...@googlegroups.com
Thanks, that was the problem.

Diego Lorden

unread,
Dec 4, 2014, 6:30:39 PM12/4/14
to django-rest-...@googlegroups.com
Any plans to support DRF 3.0 soon?


On Thursday, December 4, 2014 9:24:42 AM UTC-8, dmeehan wrote:

Nemesis

unread,
Dec 5, 2014, 4:08:58 AM12/5/14
to django-rest-...@googlegroups.com
On 12/05/2014 12:30 AM, Diego Lorden wrote:
Any plans to support DRF 3.0 soon?

Personally, I'm not in urgent need, so I'm not planning to do it urgently.

Nemesis

unread,
Dec 5, 2014, 5:28:42 AM12/5/14
to django-rest-...@googlegroups.com
I'd say I'll definitely do it before mid january, but i cannot guarantee.

Fed.
Reply all
Reply to author
Forward
0 new messages