Example #1
0
 def __getmodel(self):
     """
     Returns the Django model that materializes this concept. This is either 
     the RDF Resource model (in case of a generic concept) or some other model 
     that stores only instances of this exact concept.
     """
     return import_class(self.model_name)
Example #2
0
 def __getitem__(self, name):
     """
     This is a highly convenient shorthand that supports expressions like 
     
         RDF['Property', 'about', 'subject', 'predicate', 'object']
         
     and returns instances of the appropriate models - in the example above, 
     a concept and for predicates. 
     
     It somewhat unfortunately can't be used in any code that might be invoked 
     from the templating system. 
     """
     if not self._dict_enabled:
         return super(Namespace, self).__getitem__(name)
     if type(name) in (tuple, list):
         return [self[i] for i in name]
     r = Resource.objects.get(namespace=self, name=name)
     if not r.type is Resource:
         Model = import_class(r.type.model_name) # IGNORE:W0621
         if not Model is Resource:
             r = Model.objects.get(resource=r)
     return r