djangordf.properties¶
Declarative property descriptors. Each property owns its RDF
serialisation (to_rdf) and deserialisation (from_rdf) and supports
many=True/False cardinality.
Declarative property descriptors for RDFModel.
Property type system (issue #7). The metaclass collects Property
instances at class creation, hands each one the owner class via
contribute_to_class, and later delegates RDF serialisation /
deserialisation to to_rdf / from_rdf per property.
- class djangordf.properties.Property(predicate=None, *, many=False, required=False, default=None)[source]¶
Bases:
objectBase class for declarative property descriptors.
Subclasses override
to_rdfandfrom_rdfto map Python values to RDF terms and back. The base implementation is a no-op so simple direct uses ofPropertykeep working — useful for tests that only need a predicate stub.
- class djangordf.properties.DataProperty(predicate=None, *, datatype=None, many=False, required=False, default=None)[source]¶
Bases:
PropertyTyped-literal data property (xsd:string, xsd:integer, …).
- class djangordf.properties.LangStringProperty(predicate=None, *, many=False, required=False, default=None)[source]¶
Bases:
PropertyLanguage-tagged string property mapping to
rdf:langString.
- class djangordf.properties.URIProperty(predicate=None, *, many=False, required=False, default=None)[source]¶
Bases:
PropertyRaw-IRI property (no Python wrapper, just
URIRef).
- class djangordf.properties.ObjectProperty(target, predicate=None, *, many=False, required=False, default=None, inverse=None, reverse=False)[source]¶
Bases:
PropertyLink between two RDFModel instances.
targetmay be the target class, the string"self", or the name of a registered model class — the last two resolve lazily throughdjangordf.models.get_registered_modelthe first timetarget_classis accessed.inversenames a property declared on the target class. When present, saving an instance also writes the mirror triple(target.iri, inverse_predicate, self.iri)and deletes any stale mirror triples pointing at this instance via the inverse predicate. The resolution is lazy — accessinginverse_propertyorinverse_predicatefor the first time looks up the referenced attribute on the target class.reverse=Truedeclares a read-only virtual property whose triples live on the target class’s forward predicate. Saving an instance emits no triples for this property; reading hydrates target-class ghost instances by looking up subjects that point at this instance viapredicate. Filter paths through a reverse segment swap subject and object so the generated SPARQL traverses the inverse direction.reverse=Trueis mutually exclusive withinverse=<name>(the latter implies mirror writes, which contradicts read-only semantics).- Parameters:
- property target_class¶
- property inverse_property¶
Resolve
inverseto the matchingPropertyon the target class. ReturnsNoneif no inverse was declared; raisesValueErrorif the name does not resolve.
- property inverse_predicate¶
URIRefpredicate of the resolved inverse property, orNoneif no inverse was declared.