accounts package

Submodules

accounts.admin module

class accounts.admin.CustomUserAdmin(model, admin_site)[source]

Bases: UserAdmin

Accounts (CustomUser) Administration customization

add_form

alias of CustomUserCreationForm

form

alias of CustomUserChangeForm

list_display = ['email', 'username', 'is_staff', 'is_active']
property media
model

alias of CustomUser

accounts.apps module

Accounts App (CustomUser records) Configuration

class accounts.apps.AccountsConfig(app_name, app_module)[source]

Bases: AppConfig

default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
ready()[source]

Override this method in subclasses to run code when Django starts.

accounts.forms module

class accounts.forms.CustomUserChangeForm(*args, **kwargs)[source]

Bases: UserChangeForm

Form fields:

  • email: Email address (EmailField)

  • username: Username (CharField)

  • password: Password (ReadOnlyPasswordHashField)

property media

Return all media required to render the widgets on this form.

class accounts.forms.CustomUserCreationForm(*args, **kwargs)[source]

Bases: AdminUserCreationForm

Form fields:

property media

Return all media required to render the widgets on this form.

accounts.models module

Accounts model (CustomUser records) for storing users customized to allow login by email, etc.

Mix in SafeDeleteManager into CustomUserManager for Soft Deletes using safedelete

class accounts.models.CustomUser(*args, **kwargs)[source]

Bases: BaseModel, AbstractUser

Database table: accounts_customuser

CustomUser model - Abstract User customized to allow login by email

Mix in BaseModel to provide: - soft deletes using django-safedelete

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.

  • first_name (CharField) – First name

  • last_name (CharField) – Last name

  • 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

  • deleted (DateTimeField) – Deleted

  • deleted_by_cascade (BooleanField) – Deleted by cascade

  • created_at (DateTimeField) – Created at

  • updated_at (DateTimeField) – Updated at

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)

  • history (AuditlogHistoryField to LogEntry) – History (related name: +)

Reverse relationships:

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

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

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

created_at

Type: DateTimeField

Created at

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

date_joined

Type: DateTimeField

Date joined

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

deleted

Type: DateTimeField

Deleted

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

deleted_by_cascade

Type: BooleanField

Deleted by cascade

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 custom 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

first_name

Type: CharField

First name

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

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

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

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_next_by_updated_at(*, field=<django.db.models.DateTimeField: updated_at>, is_next=True, **kwargs)

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

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

Finds previous instance based on created_at. See get_previous_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.

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

Finds previous instance based on updated_at. 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

history

Type: Reverse AuditlogHistoryField from CustomUser

All + of this log entry (related name of history)

Accessor to the related objects manager on the one-to-many relation created by GenericRelation.

In the example:

class Post(Model):
    comments = GenericRelation(Comment)
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

last_name

Type: CharField

Last name

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 custom 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_or_email()[source]

Return the user’s full name, otherwise return their email.

objects = <accounts.models.CustomUserManager object>
password

Type: CharField

Password

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

updated_at

Type: DateTimeField

Updated at

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

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

class accounts.models.CustomUserManager(*args, **kwargs)[source]

Bases: SafeDeleteManager, UserManager

Custom User model Manager class (‘objects’).

Manager class for CustomUsers (Accounts). Access to this class is through the ‘objects’ instance attribute of the CustomUser Class.

Soft Delete of Users are implemented through SafeDelete. See: https://django-safedelete.readthedocs.io/en/latest/managers.html

Parameters:
  • param1 (class) – SafeDelete manager class mixin

  • param2 (class) – UserManager for CustomUser Abstract Class

all_deleted()[source]

Returns all soft deleted customuser records.

Todo

replace accounts.models.CustomUserManager.all_deleted with SafeDeleteManager.deleted_only()

No arguments are passed to this function when calling it

Returns:

The soft deleted custom user records.

Return type:

recordset

Example

# Print out all deleted records
for rec in Account.all_deleted():
    print(rec)

accounts.signals module

accounts.signals.email_is_also_username(sender, instance, **kwargs)[source]

Force the username field to be the same as the email field

Prevent duplication of email addresses in the CustomUser model at the database level.

We are using a pre_save signal decorator to force username field to be set to the records email field value for all CustomUser records

accounts.views module

Module contents