-
-
Save anonymous/e1651e89eb05e0634511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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