Note that there are some explanatory texts on larger screens.

plurals
  1. POTastypie Neo4django 'unicode' object has no attribute 'pk'
    primarykey
    data
    text
    <p>I use Tastypie with neo4django. I follow <a href="https://gist.github.com/mhluongo/5789513" rel="nofollow">https://gist.github.com/mhluongo/5789513</a> and <a href="http://django-tastypie.readthedocs.org/en/latest/interacting.html" rel="nofollow">http://django-tastypie.readthedocs.org/en/latest/interacting.html</a>. Now I stuck in overgiving the value for some relations (via the resource_uri?!) while the POST or PUT of (new) submissions. "'unicode' object has no attribute 'pk'". </p> <p>submission.py </p> <pre><code>from neo4django.db import models from core.models.user import AppUser from core.models.slide import Slide class Submission(models.NodeModel): value = models.ArrayProperty() started = models.DateTimeProperty() finished = models.DateTimeProperty() user = models.Relationship(AppUser, rel_type='answered_by', single=True, related_name='submissions' ) slide = models.Relationship(Slide, rel_type='response_to', single=True, related_name='submissions' ) </code></pre> <p>api.py </p> <pre><code>class UserResource(ModelResource): class Meta: queryset = AppUser.objects.all() resource_name = 'user' excludes = ['password'] allowed_methods = ['get'] authentication = BasicAuthentication() class SlideResource(ModelResource): class Meta: queryset = Slide.objects.all() resource_name = 'slide' excludes = ['answers', 'require_order', 'require_all'] authorization = Authorization() class SubmissionResource(ModelResource): class Meta: queryset = Submission.objects.all() resource_name = 'submission' excludes = ['require_order', 'require_all'] authorization = Authorization() </code></pre> <p>urls.py </p> <pre><code>from django.conf.urls import patterns, include, url from api.api import * user_resource = UserResource() slide_resource = SlideResource() submission_resource = SubmissionResource() urlpatterns = patterns('', url(r'^api/', include(user_resource.urls)), url(r'^api/', include(slide_resource.urls)), url(r'^api/', include(submission_resource.urls)), ) </code></pre> <p>curl .../submission/schema/</p> <pre><code>{"allowed_detail_http_methods": ["get", "post", "put", "delete", "patch"], "allowed_list_http_methods": ["get", "post", "put", "delete", "patch"], "default_format": "application/json", "default_limit": 20, "fields": {"finished": {"blank": false, "default": "No default provided.", "help_text": "A date &amp; time as a string. Ex: \"2010-11-10T03:07:43\"", "nullable": true, "readonly": false, "type": "datetime", "unique": false}, "id": {"blank": true, "default": "", "help_text": "Integer data. Ex: 2673", "nullable": false, "readonly": false, "type": "integer", "unique": true}, "resource_uri": {"blank": false, "default": "No default provided.", "help_text": "Unicode string data. Ex: \"Hello World\"", "nullable": false, "readonly": true, "type": "string", "unique": false}, "slide": {"blank": true, "default": "", "help_text": "Unicode string data. Ex: \"Hello World\"", "nullable": false, "readonly": false, "type": "string", "unique": false}, "started": {"blank": false, "default": "No default provided.", "help_text": "A date &amp; time as a string. Ex: \"2010-11-10T03:07:43\"", "nullable": true, "readonly": false, "type": "datetime", "unique": false}, "user": {"blank": true, "default": "", "help_text": "Unicode string data. Ex: \"Hello World\"", "nullable": false, "readonly": false, "type": "string", "unique": false}, "value": {"blank": false, "default": "No default provided.", "help_text": "Unicode string data. Ex: \"Hello World\"", "nullable": true, "readonly": false, "type": "string", "unique": false}}} </code></pre> <p>Error: </p> <pre><code>HTTP/1.1 500 INTERNAL SERVER ERROR Server: nginx/1.1.19 Date: Sat, 09 Nov 2013 15:20:35 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive {"error_message": "'unicode' object has no attribute 'pk'", "traceback": "Traceback (most recent call last):\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/tastypie/resources.py\", line 195, in wrapper\n response = callback(request, *args, **kwargs)\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/tastypie/resources.py\", line 435, in dispatch_detail\n return self.dispatch('detail', request, **kwargs)\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/tastypie/resources.py\", line 458, in dispatch\n response = method(request, **kwargs)\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/tastypie/resources.py\", line 1408, in put_detail\n updated_bundle = self.obj_update(bundle=bundle, **self.remove_api_resource_names(kwargs))\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/tastypie/resources.py\", line 2144, in obj_update\n return self.save(bundle, skip_errors=skip_errors)\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/tastypie/resources.py\", line 2230, in save\n bundle.obj.save()\n\n File \"/opt/phaidra/env/src/neo4django/neo4django/db/models/base.py\", line 315, in save\n return super(NodeModel, self).save(using=using, **kwargs)\n\n File \"/opt/phaidra/env/local/lib/python2.7/site-packages/django/db/models/base.py\", line 546, in save\n force_update=force_update, update_fields=update_fields)\n\n File \"/opt/phaidra/env/src/neo4django/neo4django/db/models/base.py\", line 333, in save_base\n self._save_neo4j_relationships(self, self.__node)\n\n File \"/opt/phaidra/env/src/neo4django/neo4django/db/models/relationships.py\", line 333, in _save_\n rels[key]._save_relationship(instance, node, state[key])\n\n File \"/opt/phaidra/env/src/neo4django/neo4django/db/models/relationships.py\", line 499, in _save_relationship\n rels.single = self._create_neo_relationship(node, other)\n\n File \"/opt/phaidra/env/src/neo4django/neo4django/db/models/relationships.py\", line 377, in _create_neo_relationship\n if obj.pk is None: AttributeError: 'unicode' object has no attribute 'pk'\n"} </code></pre> <p>Setting non-relation attributes works fine. Creating a new submission returns the same error, but creation is done without the "crashed" relations. I wonder if this should not work as well with the ModelRessource for neo4django. Thanks a lot.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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