democrasite.users.models module

Models related to users and accounts.

Starting a new project, it’s highly recommended to set up a custom user model, even if the default User model is sufficient.

This model behaves identically to the default user model, but it can be customized in the future if the need arises.

Additional fields can be added to the model in other apps by creating a new model with a OneToOneField to the User model.

class democrasite.users.models.User(*args, **kwargs)

Bases: AbstractUser

Default user for Democrasite.

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

  • password (CharField) – Password

  • last_login (DateTimeField) – Last login

  • is_superuser (BooleanField) – Superuser status. Designates that this user has all permissions without explicitly assigning them.

  • username (CharField) – Username. Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.

  • email (EmailField) – Email address

  • is_staff (BooleanField) – Staff status. Designates whether the user can log into this admin site.

  • is_active (BooleanField) – Active. Designates whether this user should be treated as active. Unselect this instead of deleting accounts.

  • date_joined (DateTimeField) – Date joined

  • name (CharField) – Name of User

Relationship fields:

Parameters:
  • groups (ManyToManyField to Group) – Groups. The groups this user belongs to. A user will get all permissions granted to each of their groups. (related name: user_set)

  • user_permissions (ManyToManyField to Permission) – User permissions. Specific permissions for this user. (related name: user_set)

Reverse relationships:

Parameters:
  • emailaddress (Reverse ForeignKey from EmailAddress) – All email addresses of this user (related name of user)

  • socialaccount (Reverse ForeignKey from SocialAccount) – All social accounts of this user (related name of user)

  • auth_token (Reverse OneToOneField from Token) – The auth token of this user (related name of user)

  • outstandingtoken (Reverse ForeignKey from OutstandingToken) – All Outstanding Tokens of this user (related name of user)

  • vote (Reverse ForeignKey from Vote) – All votes of this user (related name of user)

  • bill (Reverse ForeignKey from Bill) – All bills of this user (related name of author)

  • votes (Reverse ManyToManyField from Bill) – All votes of this user (related name of votes)

  • person (Reverse OneToOneField from Person) – The person of this user (related name of user)

  • logentry (Reverse ForeignKey from LogEntry) – All log entries of this user (related name of user)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

auth_token

Type: Reverse OneToOneField from Token

The auth token of this user (related name of user)

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

In the example:

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

Type: Reverse ForeignKey from Bill

All bills of this user (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

date_joined

Type: DateTimeField

Date joined

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

email

Type: EmailField

Email address

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

emailaddress_set

Type: Reverse ForeignKey from EmailAddress

All email addresses of this user (related name of user)

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 url for user’s detail view.

Returns:

URL for user detail.

Return type:

str

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

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

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

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

groups

Type: ManyToManyField to Group

Groups. The groups this user belongs to. A user will get all permissions granted to each of their groups. (related name: user_set)

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

id

Type: BigAutoField

Primary key: ID

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

is_active

Type: BooleanField

Active. Designates whether this user should be treated as active. Unselect this instead of deleting accounts.

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

is_staff

Type: BooleanField

Staff status. Designates whether the user can log into this admin site.

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

is_superuser

Type: BooleanField

Superuser status. Designates that this user has all permissions without explicitly assigning them.

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

last_login

Type: DateTimeField

Last login

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

logentry_set

Type: Reverse ForeignKey from LogEntry

All log entries of this user (related name of user)

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

name

Type: CharField

Name of User

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

outstandingtoken_set

Type: Reverse ForeignKey from OutstandingToken

All Outstanding Tokens of this user (related name of user)

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

password

Type: CharField

Password

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

person

Type: Reverse OneToOneField from Person

The person of this user (related name of user)

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

In the example:

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

Type: Reverse ForeignKey from SocialAccount

All social accounts of this user (related name of user)

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

user_permissions

Type: ManyToManyField to Permission

User permissions. Specific permissions for this user. (related name: user_set)

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

username

Type: CharField

Username. Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.

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

vote_set

Type: Reverse ForeignKey from Vote

All votes of this user (related name of user)

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

votes

Type: Reverse ManyToManyField from Bill

All votes of this user (related name of votes)

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