> that related Document may well be an Article, which in turn is related
> to a Periodical.
>
> I need to be able to grab those periodical titles where appropriate
> from a template, so am imagining chaining the 'recalls' attribute so
> that I can do:
>
> print x.recalls.periodical.title
>
> So is the right approach?
I would think what you want is
print x.recalls.title
That seems natural to me... x.recalls returns a BIBO:Document and you
get the title of the document. Now if the issue is that for an
article, you want the periodical title and not the article title then
you do have to change your approach.
If that is the case, the "change" appears localized to the Bookmark
class. that means that a Bookmark title is a different animal.
how about an approach more like:
class Bookmark(rdfSubject):
rdf_type = BM['Bookmark']
# a problem if the range is an Article
recalls = rdfSingle(BM.recalls, range_type=BIBO.Document)
@property
def title(self):
doc = self.recalls
if BIBO.Article == doc[RDF.type]:
return doc.periodical.title
# or maybe return doc.isPartOf.title
# or whaever works
else:
return doc.title
The approach here is to define a custom "property" that does a small bit
of custom logic you want.
Then you just use:
x.title
--
Phil