democrasite.activitypub.models module

Models for the activitypub app.

class democrasite.activitypub.models.Follow(*args, **kwargs)

Bases: Model

Timestamped record of a person following another

Parameters:

Relationship fields:

Parameters:
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

created

Type: DateTimeField

Created

A wrapper for a deferred-loading field. When the value is read from this

follower

Type: ForeignKey to Person

Follower (related name: following_set)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
follower_id

Internal field, use follower instead.

following

Type: ForeignKey to Person

Following (related name: follower_set)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
following_id

Internal field, use following instead.

get_next_by_created(*, field=<django.db.models.DateTimeField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<django.db.models.DateTimeField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

objects = <django.db.models.Manager object>
class democrasite.activitypub.models.Like(*args, **kwargs)

Bases: Model

A model to represent a like on a Note by a Person.

Parameters:

Relationship fields:

Parameters:
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

created

Type: DateTimeField

Created

A wrapper for a deferred-loading field. When the value is read from this

get_next_by_created(*, field=<django.db.models.DateTimeField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<django.db.models.DateTimeField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

note

Type: ForeignKey to Note

Note (related name: like)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
note_id

Internal field, use note instead.

objects = <django.db.models.Manager object>
person

Type: ForeignKey to Person

Person (related name: like)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
person_id

Internal field, use person instead.

class democrasite.activitypub.models.Note(*args, **kwargs)

Bases: TimeStampedModel, MPTTModel

A note in the ActivityPub network, representing a short piece of content.

Parameters:

Relationship fields:

Parameters:

Reverse relationships:

Parameters:
  • like (Reverse ForeignKey from Like) – All likes of this note (related name of note)

  • repost (Reverse ForeignKey from Repost) – All reposts of this note (related name of note)

  • replies (Reverse TreeForeignKey from Note) – All replies of this note (related name of in_reply_to)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

author

Type: ForeignKey to Person

Author (related name: notes)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
author_id

Internal field, use author instead.

content

Type: TextField

Content

A wrapper for a deferred-loading field. When the value is read from this

created

Type: AutoCreatedField

Created

A wrapper for a deferred-loading field. When the value is read from this

get_absolute_url()

Get the URL for the note’s detail view.

Returns:

URL for the note detail.

Return type:

str

get_like_url()
get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)

Finds next instance based on modified. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)

Finds previous instance based on modified. See get_previous_by_FOO() for more information.

get_repost_url()
history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>
id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

in_reply_to

Type: TreeForeignKey to Note

In reply to (related name: replies)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
in_reply_to_id

Internal field, use in_reply_to instead.

level

Type: PositiveIntegerField

Level

A wrapper for a deferred-loading field. When the value is read from this

lft

Type: PositiveIntegerField

Lft

A wrapper for a deferred-loading field. When the value is read from this

like(person: Person) bool

Toggle a like on the note for a person.

Parameters:

person (Person) – The person liking or unliking the note.

Returns:

True if the like was added, False if it was removed.

Return type:

bool

like_set

Type: Reverse ForeignKey from Like

All likes of this note (related name of note)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

liked_by(person: Person) bool

Check if a person has liked the note.

Parameters:

person (Person) – The person to check for a like.

Returns:

True if the person has liked the note, False otherwise.

Return type:

bool

likes

Type: ManyToManyField to Person

Likes (related name: likes)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

modified

Type: AutoLastModifiedField

Modified

A wrapper for a deferred-loading field. When the value is read from this

objects = <democrasite.activitypub.models.NoteManager object>
replies

Type: Reverse TreeForeignKey from Note

All replies of this note (related name of in_reply_to)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

repost(person: Person) bool

Toggle a repost on the note for a person.

Parameters:

person (Person) – The person reposting or un-reposting the note.

Returns:

True if the repost was added, False if it was removed.

Return type:

bool

repost_set

Type: Reverse ForeignKey from Repost

All reposts of this note (related name of note)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

reposted_by(person: Person) bool

Check if a person has reposted the note.

Parameters:

person (Person) – The person to check for a repost.

Returns:

True if the person has reposted the note, False otherwise.

Return type:

bool

reposts

Type: ManyToManyField to Person

Reposts (related name: reposts)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

rght

Type: PositiveIntegerField

Rght

A wrapper for a deferred-loading field. When the value is read from this

save_without_historical_record(*args, **kwargs)

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

tree_id

Type: PositiveIntegerField

Tree id

A wrapper for a deferred-loading field. When the value is read from this

class democrasite.activitypub.models.NoteManager(*args, **kwargs)

Bases: TreeManager

get_person_following_notes(person: Person) QuerySet

Get notes from people the person is following.

This method retrieves all notes authored or reposted by people that the specified person is following, ordered by the creation or repost time of the notes. This method removes duplicate notes.

Parameters:

person (Person) – The person whose following notes are to be retrieved.

Returns:

A queryset of notes and reposts from followed persons, ordered by time.

Return type:

models.QuerySet[T]

get_person_notes(person: Person) QuerySet

Get notes for display on a person’s profile page.

This method returns all notes authored by the person as well as all their reposts, ordered by their creation or repost time. Reposts are annotated with the reposted_by and reposted_at fields for use in templates. If a user has reposted their own note, both the original note and the repost will be included in the results.

Parameters:

person (Person) – The person whose notes and reposts are to be retrieved.

Returns:

A queryset of notes and reposts ordered by time.

Return type:

models.QuerySet[T]

get_queryset() QuerySet

Get the queryset for notes, ordered by creation date.

class democrasite.activitypub.models.Person(*args, **kwargs)

Bases: TimeStampedModel

A person in the ActivityPub network, linked to a Django User.

Parameters:
  • id (BigAutoField) – Primary key: ID

  • created (AutoCreatedField) – Created

  • modified (AutoLastModifiedField) – Modified

  • private_key (TextField) – Private key

  • public_key (TextField) – Public key

  • bio (TextField) – Bio. A short biography or description of the person

Relationship fields:

Parameters:

Reverse relationships:

Parameters:
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

bio

Type: TextField

Bio. A short biography or description of the person

A wrapper for a deferred-loading field. When the value is read from this

created

Type: AutoCreatedField

Created

A wrapper for a deferred-loading field. When the value is read from this

property display_name

Get the display name for the person.

Returns:

The username of the person.

Return type:

str

follow(person: Person) bool

Toggle whether this person follows another person.

Parameters:

person (Person) – The person following or unfollowing this person.

Returns:

True if the follow was added, False if it was removed.

Return type:

bool

follower_set

Type: Reverse ForeignKey from Follow

All follower set of this person (related name of following)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

followers

Type: Reverse ManyToManyField from Person

All followers of this person (related name of following)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

following

Type: ManyToManyField to Person

Following. People this person is following (related name: followers)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

following_set

Type: Reverse ForeignKey from Follow

All following set of this person (related name of follower)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

get_absolute_url()

Get the URL for the person’s detail view.

Returns:

URL for the person detail.

Return type:

str

get_follow_url()
get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)

Finds next instance based on modified. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)

Finds previous instance based on modified. See get_previous_by_FOO() for more information.

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>
id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

is_following(person: Person) bool

Check if a person is following this person.

Parameters:

person (Person) – The person to check for a follow.

Returns:

True if the person is following this person, False otherwise.

Return type:

bool

like_set

Type: Reverse ForeignKey from Like

All likes of this person (related name of person)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

likes

Type: Reverse ManyToManyField from Note

All likes of this person (related name of likes)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

modified

Type: AutoLastModifiedField

Modified

A wrapper for a deferred-loading field. When the value is read from this

notes

Type: Reverse ForeignKey from Note

All notes of this person (related name of author)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

objects = <democrasite.activitypub.models.PersonManager object>
private_key

Type: TextField

Private key

A wrapper for a deferred-loading field. When the value is read from this

public_key

Type: TextField

Public key

A wrapper for a deferred-loading field. When the value is read from this

repost_set

Type: Reverse ForeignKey from Repost

All reposts of this person (related name of person)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

reposts

Type: Reverse ManyToManyField from Note

All reposts of this person (related name of reposts)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

save_without_historical_record(*args, **kwargs)

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

user

Type: OneToOneField to User

User (related name: person)

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')
user_id

Internal field, use user instead.

class democrasite.activitypub.models.PersonManager(*args, **kwargs)

Bases: Manager

Manager for Person model with user prefetched.

get_queryset()

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class democrasite.activitypub.models.Repost(*args, **kwargs)

Bases: Model

A model to represent a repost of a Note by a Person.

Parameters:

Relationship fields:

Parameters:
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

created

Type: DateTimeField

Created

A wrapper for a deferred-loading field. When the value is read from this

get_next_by_created(*, field=<django.db.models.DateTimeField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<django.db.models.DateTimeField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

note

Type: ForeignKey to Note

Note (related name: repost)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
note_id

Internal field, use note instead.

objects = <django.db.models.Manager object>
person

Type: ForeignKey to Person

Person (related name: repost)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
person_id

Internal field, use person instead.