Skip to content

anonymous /one2oneIssue secret

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
class Relation(MP_Node): # from django-treebeard
#..snip..
peerRel = models.OneToOneField('Relation', editable=False, null=True, default=None)
class Identity(models.Model):
#..snip..
relation = models.OneToOneField('Relation', related_name='identity', editable=False, default=None)
peerIdentity = models.OneToOneField('Identity', editable=False, null=True, default=None)
# myRel is an instance of Relation
# myId is an instance of Identity
# myId.peerIdentity points to another instance of Identity
>>> myRel.identity == myId
True
>>> myId.peerIdentity
<Identity: worksheet: id: 6, title: root 3, self_id: , peer_tag >
# so this shows up
>>> myRel.identity.peerIdentity
>>>
# but why not this?
UPDATE:
>>> myId.peerIdentity
<Identity: worksheet: id: 6, title: root 3, self_id: , peer_tag >
>>> myId.save()
>>> myId.peerIdentity
<Identity: worksheet: id: 6, title: root 3, self_id: , peer_tag >
>>> myId.id
5
>>> myId_n=Identity.objects.get(id=5)
>>> myId_n.peerIdentity
>>>
UPDATE
On the model: Identity and Relation both come in coupled pairs, ie. each instance points to its paired instance, plus an individual ForeignKey.
This is to enable symmetrical access via ForeignKey but still keep asymmetrical information about the Identity/Relation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.