Skip to content

Model Reference

Django ActivityPub Toolkit uses several categories of models to represent ActivityPub data structures, federation state, and application-specific entities.

Core Federation Models

These models manage the fundamental entities for ActivityPub federation.

Domains and References

activitypub.models.Domain

Bases: TimeStampedModel

activitypub.models.Reference

Bases: StatusModel

The Reference is the base class for any JSON-LD context.

activitypub.models.LinkedDataDocument

Bases: Model

A linked data document contains only the source JSON-LD documents

activitypub.models.ActivityPubServer

Bases: Model

Field Types

activitypub.models.ReferenceField

Bases: Field

Custom field that links via reference FKs instead of model PKs.

Creates a through table that links source_reference_id to target_reference_id, allowing queries without requiring the source instance to have a pk.

This field should only be used on models that have a 'reference' ForeignKey to the Reference model.

Example

class ObjectContext(AbstractContextModel): reference = models.OneToOneField(Reference, on_delete=models.CASCADE) source = ReferenceField()

Works even if obj is unsaved:

obj = ObjectContext(reference=some_ref) related_refs = obj.source.all() # Queries via obj.reference, not obj.pk

Override to prevent reverse relation setup. ReferenceField doesn't support reverse relations.

db_parameters(connection)

Override to ensure no database column is created.

db_type(connection)

ReferenceField doesn't have a database column. The relationship is stored in the through table.

deconstruct()

Return enough information to recreate the field as a 4-tuple. Used by migrations.

get_attname_column()

Override to prevent Django from creating a database column. Returns (attname, None) to indicate no column should be created.

get_internal_type()

Return the internal field type identifier.

get_lookup(lookup_name)

Override to provide custom lookups for ReferenceField filtering.

This enables QuerySet filtering like

SecV1Context.objects.filter(owner=actor_ref) SecV1Context.objects.filter(owner__in=[ref1, ref2]) SecV1Context.objects.filter(owner__isnull=True)

get_prep_value(value)

Convert Reference instances to their PKs for database queries.

m2m_field_name()

Return the name of the FK field on the through table that points to the source model.

For ReferenceField, this is 'source_reference' instead of the default.

m2m_reverse_field_name()

Return the name of the FK field on the through table that points to the target model.

For ReferenceField, this is 'target_reference' instead of the default.

m2m_reverse_target_field_name()

Return the name of the field on the source model.

m2m_target_field_name()

Return the name of the field on the target model.

to_python(value)

Convert database value to Python object. For ReferenceField, this is handled by the descriptor/manager.

activitypub.models.RelatedContextField

Accounts and Actors

activitypub.models.ActorAccount

Bases: AbstractBaseUser

ActivityStreams Context Models

These models store ActivityStreams 2.0 vocabulary data attached to references.

Core Types

activitypub.models.LinkContext

Bases: AbstractContextModel

activitypub.models.as2.AbstractAs2ObjectContext

Bases: AbstractContextModel

ActivityStreams 2.0 vocabulary context. Stores AS2-specific fields like name, type, published, actor, etc.

activitypub.models.ActorContext

Bases: BaseAs2ObjectContext

activitypub.models.ActivityContext

Bases: BaseAs2ObjectContext

activitypub.models.QuestionContext

Bases: AbstractContextModel

Collections

activitypub.models.CollectionContext

Bases: BaseCollectionContext

activitypub.models.CollectionPageContext

Bases: BaseCollectionContext

activitypub.models.CollectionItem

Bases: Model

Extended Properties

activitypub.models.EndpointContext

Bases: AbstractContextModel

activitypub.models.LinkRelation

Bases: Model

activitypub.models.RelationshipProperties

Bases: Model

activitypub.models.LinkedFile

Bases: Model

Reference Relationships

activitypub.models.fields.ReferenceRelationship

Bases: Model

Base through model for ReferenceField relationships.

This creates a many-to-many relationship between References, linking source_reference to target_reference instead of source_model to target_model.

activitypub.models.fields.ContextProxy

save()

Save the context if it's been modified

Social Features

activitypub.models.FollowRequest

Bases: StatusModel, TimeStampedModel