Note that there are some explanatory texts on larger screens.

plurals
  1. POError using ModelResource: can't set attribute
    primarykey
    data
    text
    <p>I can't get my head around this error... I'm using the <a href="https://github.com/tomchristie/django-rest-framework/tree/restframework2" rel="nofollow">restframework2</a> branch.</p> <p>Am I doing something wrong, or is this a bug in the restframework2 code?</p> <p>Here's my code:</p> <p><em>resources.py</em></p> <pre><code>class TemplateHoursSerializer(serializers.ModelSerializer): class Meta: model = TemplateHours nested = True start = HourField() end = HourField() employee = EmployeeSerializer() class TemplateHoursResource(ModelResource): model = TemplateHours serializer_class = TemplateHoursSerializer </code></pre> <p><em>urls.py</em></p> <pre><code>url(r'^api/template-hours/$', TemplateHoursResource.as_view(actions={ 'get': 'list', 'post': 'create' })), url(r'^api/template-hours/(?P&lt;pk&gt;[0-9]+)/$', TemplateHoursResource.as_view(actions={ 'get': 'retrieve', 'put': 'update', 'delete': 'destroy' })), ... </code></pre> <p>When I visit (or POST to) <code>http://127.0.0.1:8000/api/template-hours/</code>, I get this error and traceback:</p> <pre><code>AttributeError at /api/template-hours/ can't set attribute Request Method: GET Request URL: http://127.0.0.1:8000/api/template-hours/ Django Version: 1.4.1 Exception Type: AttributeError Exception Value: can't set attribute Exception Location: C:\Users\Mathieu\Development\django_projects\hedron\Lib\site- packages\rest_framework\resources.py in wrapped, line 13 Python Executable: C:\Python27\python.exe Python Version: 2.7.2 Python Path: ['C:\\Users\\Mathieu\\Development\\django_projects\\hedron\\Scripts', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c12dev_r88846-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\virtualenv-1.7.1.2-py2.7.egg', 'C:\\Users\\Mathieu\\Development\\django_projects\\hedron\\Lib\\site-packages', 'C:\\Users\\Mathieu\\Development\\django_projects\\hedron\\hedron', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', path(u'C:\\Users\\Mathieu\\Development\\django_projects\\hedron'), path(u'C:\\Users\\Mathieu\\Development\\django_projects\\hedron\\hedron\\apps'), path(u'C:\\Users\\Mathieu\\Development\\django_projects\\hedron\\hedron\\libs')] Server time: di, 9 Okt 2012 22:46:50 +0200 Traceback: File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\rest_framework\resources.py" in view 48. return self.dispatch(request, *args, **kwargs) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\django\views\decorators\csrf.py" in wrapped_view 77. return view_func(*args, **kwargs) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\rest_framework\views.py" in dispatch 324. response = self.handle_exception(exc) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\rest_framework\views.py" in dispatch 321. response = handler(request, *args, **kwargs) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\rest_framework\resources.py" in list 74. return self.root_view().list(request, args, kwargs) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\rest_framework\resources.py" in root_view 68. return wrapped(self, self.root_class()) File "C:\Users\Mathieu\Development\django_projects\hedron\Lib\site-packages\rest_framework\resources.py" in wrapped 13. setattr(dest, attr, getattr(source, attr)) Exception Type: AttributeError at /api/template-hours/ Exception Value: can't set attribute </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload