Suppose I have an object in /school1/document-rules
.
Suppose in another context, /school2
, I need to have the same document-rules
that is available in /school1/document-rules
.
In ZODB, having /school1/document-rules
and /school2/document-rules
means I have two different objects.
I would like to know if it's possible to make /school2/document-rules
reference /school1/document-rules
. So, /school2/document-rules
would be something like a "ReferenceDocument", "ReferenceLink" or something like a symbolic link that would just point to /school1/document-rules
.
Why? The document is the same, but sometimes it makes more sense (in semantic terms) to have the same document in different contexts. I have portlets that are rendered depending in their context, and I don't want to duplicate document-rules
.
Does something like what I'm looking for exist? Bultin or using a module?
SimpleAlias does what you want. I've used it and it works well. You could also look at collective.alias
ZODB handles references transparently as you would expect in plain Python. You have a nice explanation here.
You should watch out for multiple references for the same object when you want to delete the object. For that you might want to use weak references for your 'symlinks' using the weakref module from ZODB which is equivalent to weakref of the Python standard library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With