add support for inheriting with a prefix
This commit is contained in:
parent
14b3fdb193
commit
75b44aa1d9
2 changed files with 21 additions and 1 deletions
|
|
@ -10,7 +10,11 @@ class Record(models.Model):
|
|||
result = {}
|
||||
|
||||
for l in self.out_links.filter(inherit=True):
|
||||
if l.prefix is None:
|
||||
result.update(l.link_to.all_metadata)
|
||||
else:
|
||||
for k,v in l.link_to.all_metadata.iteritems():
|
||||
result[l.prefix + ':' + k] = v
|
||||
|
||||
result.update(self.metadata)
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -50,3 +50,19 @@ class RecordTests(TestCase):
|
|||
|
||||
self.assertEqual(d['ex:llama_id'], 42)
|
||||
self.assertEqual(d['ex:another_property'], 23)
|
||||
|
||||
def test_metadata_inherit_with_prefix(self):
|
||||
# these records are linked and marked to inherit, with a prefix 'p'
|
||||
# this is interesting so you can inherit a related entity's metadata
|
||||
# without making a mess of the namespace
|
||||
l = Link.objects.create(
|
||||
link_from=self.r,
|
||||
link_to=self.q,
|
||||
label='ex:related_to',
|
||||
inherit=True,
|
||||
prefix='p')
|
||||
|
||||
d = self.r.all_metadata
|
||||
|
||||
self.assertEqual(d['ex:llama_id'], 42)
|
||||
self.assertEqual(d['p:ex:another_property'], 23)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue