Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly I would recommend to either use <code>Tastypie</code> - which is out of the box supported by <code>neo4django</code> - instead of <code>Django Rest Framework</code> - or use <code>Django Rest Framework</code> <code>Serializer</code> instead of the <code>ModelSerializer</code> or (worst choice in my opinion) <code>HyperlinkedModelSerializer</code>.</p> <p>As for the error you get, the problem is that <code>neo4django</code> does not return the record id, therefore you get the error.</p> <p>One solution is to override the <code>restore_object</code> function, like this, to include the ID.</p> <pre><code># User Serializer class UserSerializer(serializers.Serializer): id = serializers.IntegerField() username = serializers.CharField(max_length=30) first_name = serializers.CharField(max_length=30) last_name = serializers.CharField(max_length=30) email = serializers.EmailField() password = serializers.CharField(max_length=128) is_staff = serializers.BooleanField() is_active = serializers.BooleanField() is_superuser = serializers.BooleanField() last_login = serializers.DateTimeField() date_joined = serializers.DateTimeField() def restore_object(self, attrs, instance=None): """ Given a dictionary of deserialized field values, either update an existing model instance, or create a new model instance. """ if instance is not None: instance.id = attrs.get('ID', instance.pk) instance.username = attrs.get('Username', instance.username) instance.first_name = attrs.get('First Name', instance.first_name) instance.last_name = attrs.get('First Name', instance.last_name) instance.email = attrs.get('email', instance.email) instance.password = attrs.get('Password', instance.password) instance.is_staff = attrs.get('Staff', instance.is_staff) instance.is_active = attrs.get('Active', instance.is_active) instance.is_superuser = attrs.get('Superusers', instance.is_superuser) instance.last_login = attrs.get('Last Seen', instance.last_login) instance.date_joined = attrs.get('Joined', instance.date_joined) return instance return User(**attrs) </code></pre> <p>But I still think it's better to use <code>Tastypie</code> with <code>ModelResource</code>. Here's a gist by Matt Luongo (or Lukas Martini ?) <a href="https://gist.github.com/mhluongo/5789513" rel="nofollow">https://gist.github.com/mhluongo/5789513</a></p> <p>TIP. Where <code>Serializer</code> in <code>Django Rest Framework</code>, is <code>Resource</code> in <code>Tastypie</code> and always make sure you are using the github version of neo4django (<code>pip install -e git+https://github.com/scholrly/neo4django/#egg=neo4django</code>)</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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