Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So do you need a new node in the graph, or a copy of the Django model?</p> <p>To create a copy with the same properties (but not the same relationships) and a new in-graph node, you could try something like</p> <pre><code>p = Person.objects.create(name="John Doe") p2 = Person.objects.create(**p.node.properties) </code></pre> <p>Doing the same thing with relationships is a little more difficult, but I've done it in the past and can write up a gist if that's what you need. Alternatively, this could also all be done in Gremlin or Cypher (with neo4django's helper functions) if that's a better fit, eg</p> <pre><code>from neo4django.db import connection p = Person._neo4j_instance(connection.gremlin('results=&lt;some code that yields a copied node&gt;')) </code></pre> <p>If you just need a copy of the Django model that's a different Python object (but still attached to the same node) you might try</p> <pre><code>&gt;&gt;&gt; p = Person.objects.create(name="John Doe") &gt;&gt;&gt; p2 = Person.from_model(p) &gt;&gt;&gt; print p2.name John Doe </code></pre> <p>HTH!</p> <p>EDIT:</p> <p>How could I have forgotten- there's an included convenience method for this!</p> <pre><code>&gt;&gt;&gt; john = Person.objects.create(name="John Doe") &gt;&gt;&gt; john_2 = john.copy_model() &gt;&gt;&gt; john.name == john_2.name True </code></pre> <p>Relationships and properties are all copied, though the returned model is unsaved- they don't share a node in the graph.</p> <p>Sorry about the run around, maybe this will be a little easier. </p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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