apps.accounts.models

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

Bases: AbstractBaseUser, PermissionsMixin

A custom user model that extends Django’s built-in User model.

Fields:

email: The user’s email address (unique). phone_number: The user’s phone number (optional). is_active: Whether the user account is active. is_staff: Whether the user is a member of the staff. is_superuser: Whether the user has all permissions. date_joined: The date and time the user account was created.

USERNAME_FIELD

The field to use for authentication (email in this case).

REQUIRED_FIELDS

A list of required fields for creating a user.

__str__()[source]

Returns the user’s email address.

Managers:

objects: The manager for this model.

Meta:

verbose_name: A human-readable name for this model (singular). verbose_name_plural: A human-readable name for this model (plural).

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

REQUIRED_FIELDS = []
USERNAME_FIELD = 'email'
date_joined

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

email

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

extradata_set

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 class built by create_forward_many_to_many_manager() defined below.

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

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 class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_staff

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

logentry_set

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 class built by create_forward_many_to_many_manager() defined below.

loginattemptshistory_set

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 class built by create_forward_many_to_many_manager() defined below.

loginhistorytrail_set

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 class built by create_forward_many_to_many_manager() defined below.

objects = <apps.accounts.models.CustomUserManager object>
otp_set

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 class built by create_forward_many_to_many_manager() defined below.

phone_number

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user_permissions

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 class built by create_forward_many_to_many_manager() defined below.

uservisithistory_set

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 class built by create_forward_many_to_many_manager() defined below.

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

Bases: BaseUserManager

Custom user model manager where email is the unique identifier for authentication instead of username.

create_superuser(email, password=None, **extra_fields)[source]

Create and save a SuperUser with the given email and password.

create_user(email, password=None, **extra_fields)[source]

Create and save a User with the given email and password.

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

Bases: Model

Model for storing extra data related to user activity, such as browser, IP address, device, operating system, and location.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

browser

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

device

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=True, **kwargs)
get_previous_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ip_address

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

location

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
os

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timestamp

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

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')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id
class apps.accounts.models.LoginAttemptsHistory(*args, **kwargs)[source]

Bases: Model

Model to store a history of login attempts made by users.

Fields:

user: A foreign key to the user who made the login attempt. timestamp: The date and time of the login attempt. successful: Whether the login attempt was successful. ip_address: The IP address used to make the login attempt. user_agent: The user agent string for the browser or

other client used to make the login attempt.

location: The location (city, country) of the IP

address used to make the login attempt, if available.

Meta:

verbose_name_plural: A human-readable name for this model (plural). ordering: The default ordering for querysets of this model,

by timestamp in descending order.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_next_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=True, **kwargs)
get_previous_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ip_address

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

location

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
successful

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timestamp

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

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')

Child.parent is a ForwardManyToOneDescriptor instance.

user_agent

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user_id
class apps.accounts.models.LoginHistoryTrail(*args, **kwargs)[source]

Bases: Model

Model to store a trail of login attempts made by users.

Fields:

user: A foreign key to the user who made the login attempt. timestamp: The date and time of the login attempt. successful: Whether the login attempt was successful. ip_address: The IP address used to make the login attempt. user_agent: The user agent string for the browser or other client

used to make the login attempt.

location: The location (city, country) of the IP address used

to make the login attempt, if available.

Meta:

verbose_name_plural: A human-readable name for this model (plural). ordering: The default ordering for querysets of this model,

by timestamp in descending order.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_next_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=True, **kwargs)
get_previous_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ip_address

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

location

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
successful

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timestamp

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

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')

Child.parent is a ForwardManyToOneDescriptor instance.

user_agent

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user_id
class apps.accounts.models.OTP(*args, **kwargs)[source]

Bases: Model

Model for storing one-time passwords (OTPs) associated with a user.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod create(user)[source]

Creates a new OTP for the given user.

Parameters:

user (CustomUser) – The user associated with the new OTP.

Returns:

The newly created OTP.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get_latest(user)[source]

Gets the latest active OTP for the given user.

Parameters:

user (CustomUser) – The user associated with the OTP.

Returns:

The latest active OTP, or None if there are no active OTPs.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_valid()[source]

Checks whether or not the OTP is valid (i.e. active and not expired).

Returns:

True if the OTP is valid, False otherwise.

objects = <django.db.models.manager.Manager object>
save(*args, **kwargs)[source]

Saves the OTP to the database.

Parameters:
  • *args

  • **kwargs

Raises:

ValidationError – If the code is not a 4-digit number.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

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')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id
class apps.accounts.models.UserVisitHistory(*args, **kwargs)[source]

Bases: Model

Model to store the history of user visits to the site.

Fields:

user: A foreign key to the user who made the visit. timestamp: The date and time of the visit. url: The URL of the page visited. referer: The URL of the referring page, if any. user_agent: The user agent string for the browser

or other client used to make the visit.

Meta:

verbose_name_plural: A human-readable name for this model (plural). ordering: The default ordering for querysets of this model,

by timestamp in descending order.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_next_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=True, **kwargs)
get_previous_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
referer

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timestamp

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

url

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

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')

Child.parent is a ForwardManyToOneDescriptor instance.

user_agent

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user_id