djangonauts / django-rest-framework-hstore

Django Rest Framework tools for django-hstore
MIT License
75 stars 15 forks source link

ImportError: cannot import name 'WritableField' #5

Closed leebrooks0 closed 9 years ago

leebrooks0 commented 9 years ago

Hi

Thank you for your library, it is just what I need for the task I am working on. Unfortunately I keep getting an import error. I am using Django 1.7 and I keep getting this error:

(venv) lee@lee ~/C/cas (master)> python manage.py runserver 9000
Traceback (most recent call last):
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 364, in urlconf_module
    return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv),
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/debug_toolbar/apps.py", line 15, in ready
    dt_settings.patch_all()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/debug_toolbar/settings.py", line 238, in patch_all
    patch_root_urlconf()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/debug_toolbar/settings.py", line 226, in patch_root_urlconf
    reverse('djdt:render_panel')
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 522, in reverse
    app_list = resolver.app_dict[ns]
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 329, in app_dict
    self._populate()
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 269, in _populate
    for pattern in reversed(self.url_patterns):
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 372, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 366, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/home/lee/.pyenv/versions/3.4.2/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/lee/Code/cas/cas/urls.py", line 6, in <module>
    url(r'^api/', include('api.urls')),
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 28, in include
    urlconf_module = import_module(urlconf_module)
  File "/home/lee/.pyenv/versions/3.4.2/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/lee/Code/cas/api/urls.py", line 4, in <module>
    from api import views
  File "/home/lee/Code/cas/api/views.py", line 8, in <module>
    from api.serializers import UserSerializer
  File "/home/lee/Code/cas/api/serializers.py", line 2, in <module>
    from rest_framework_hstore.fields import HStoreField
  File "/home/lee/Code/cas/venv/lib/python3.4/site-packages/rest_framework_hstore/fields.py", line 4, in <module>
    from rest_framework.fields import WritableField
ImportError: cannot import name 'WritableField'

I tried pulling the repo locally and ran the tests:

(venv)lee@lee ~/C/django-rest-framework-hstore (master)> ./manage.py test
Creating test database for alias 'default'...
System check identified some issues:

WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
    HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.
System check identified some issues:

WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
    HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.
System check identified some issues:

WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
    HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.
System check identified some issues:

WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
    HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.
System check identified some issues:

WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
    HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.
..........
----------------------------------------------------------------------
Ran 10 tests in 0.125s

OK
Destroying test database for alias 'default'...

Am I doing something wrong?

tatchi commented 9 years ago

I think it's because you're using a 3.x version of django rest framework and it's not compatible with this module.

From: http://www.django-rest-framework.org/api-guide/fields/ you can read:

Note that the WritableField class that was present in version 2.x no longer exists. You should subclass Field and override to_internal_value() if the field supports data input.

leebrooks0 commented 9 years ago

correct, I wrote my own little custom field, if there is interest i can submit a PR, but that will break backwards compatibility

tatchi commented 9 years ago

Yes, it would be nice :) I also need to add this module to my project but didn't work for the same reason as you :(

leebrooks0 commented 9 years ago

I just created a module fields.py and then imported it in my models

from django_hstore.dict import HStoreDict
from rest_framework import serializers

class HStoreField(serializers.Field):

    def to_representation(self, value):
        return value

    def to_internal_value(self, data):
        return HStoreDict(data)
tatchi commented 9 years ago

Thank you very much :+1:

nemesifier commented 9 years ago

thank you both for contributing to the discussion, follow pull request https://github.com/djangonauts/django-rest-framework-hstore/pull/6 to stay up to date with DRF 3.1 compatibility.

I'm closing this because is a duplicate of #4.