Skip to content

Account Application Models


User Model

The User model extends Django's AbstractUser and replaces the username field with an email field for authentication.


Fields

Field Type Required Description
email EmailField Yes Unique email for the user.
has_initial_profile BooleanField No Indicates if the user has completed their initial profile.
phone CharField No User's phone number (unique).
photo ImageField No Profile picture of the user (jpg, png, jpeg).
address TextField No User's address.
gender ForeignKey No Gender of the user (nullable).
country ForeignKey No Country of the user (nullable).
birthday DateField No Birthday of the user.
created_at DateTimeField No Timestamp when the user was created (auto).
updated_at DateTimeField No Timestamp when the user was last updated (auto).
role CharField No User role with predefined choices (default: USER).

Custom Methods

  • create_user(email, password, **extra_fields)
  • Creates and saves a user with the given email and password.
  • create_superuser(email, password, **extra_fields)
  • Creates a superuser with elevated permissions.

Vendor Model

The Vendor model represents a vendor that is associated with a User model, containing company-specific details.


Fields

Field Type Required Description
user OneToOneField Yes Reference to the associated User model. (Primary Key)
company_name CharField Yes Name of the company.
telephone CharField No Vendor's company telephone number.
company_created_at DateField No Date the company was created.
company_address TextField No Address of the vendor's company.
certificate_image ImageField No Company certificate image (jpg, png, jpeg).
pan_vat_certificate_image ImageField No PAN/VAT certificate image (jpg, png, jpeg).
created_at DateTimeField No Timestamp when the vendor was created.
updated_at DateTimeField No Timestamp when the vendor was last updated.

Custom Methods

  • get_company_details()
  • Returns the details of the company associated with the vendor.

TwoFactorAuth Model

The TwoFactorAuth model holds the configuration for two-factor authentication for a User.


Fields

Field Type Required Description
user ForeignKey Yes Reference to the associated User model.
is_enabled BooleanField Yes Whether two-factor authentication is enabled.
totp_secret CharField Yes The secret key used for TOTP authentication.
created_at DateTimeField No Timestamp when the two-factor auth was created.
updated_at DateTimeField No Timestamp when the two-factor auth was last updated.

Custom Methods

  • enable_two_factor_auth()
  • Enables two-factor authentication for the user.
  • disable_two_factor_auth()
  • Disables two-factor authentication for the user.

Device Model

The Device model represents a device associated with two-factor authentication for a User.


Fields

Field Type Required Description
two_factor_auth ForeignKey Yes Reference to the TwoFactorAuth model.
device_uuid UUIDField Yes Unique identifier for the device.
device_name CharField No Name of the device (e.g., "iPhone").
login_time DateTimeField No Time when the user logged in from this device.
last_used DateTimeField No Time when the device was last used.
is_trusted BooleanField No Whether the device is trusted for authentication.
created_at DateTimeField No Timestamp when the device record was created.
updated_at DateTimeField No Timestamp when the device record was last updated.

Custom Methods

  • mark_as_trusted()
  • Marks the device as trusted.
  • remove_device()
  • Removes the device from the list of devices associated with the user.

Address Model

The Address model represents an address associated with a User.


Fields

Field Type Required Description
user ForeignKey Yes Reference to the associated User model.
name CharField Yes Name of the recipient (e.g., "John Doe").
mobile CharField Yes Mobile number for the address.
address_line_1 CharField Yes First line of the address.
address_line_2 CharField No Second line of the address.
landmark CharField No Landmark for the address.
pincode CharField Yes Pincode for the address.
country ForeignKey Yes Reference to the Country model.
state_selection ForeignKey No Reference to the State model.
state_custom CharField No input state
town_city CharField Yes Town or city for the address.
is_default BooleanField No Whether the address is the default address.
created_at DateTimeField No Timestamp when the address was created.
updated_at DateTimeField No Timestamp when the address was last updated.

Custom Methods

  • set_as_default()
  • Sets the address as the default address for the user.
  • remove_address()
  • Removes the address from the user's address list.

UserProfile Model

The UserProfile model stores additional user information such as alternative contact details and address, associated with a User.


Fields

Field Type Required Description
user ForeignKey Yes Reference to the associated User model.
alternative_mobile_number CharField No Alternative mobile number for the user.
alternative_address_line TextField No Alternative address line for the user.
landmark CharField No Landmark for the user's alternative address.
zipcode CharField No Zipcode for the user's alternative address.
city CharField No City for the user's alternative address.

Custom Methods

  • get_alternative_contact()
  • Returns the alternative mobile number and address of the user.
  • update_address()
  • Updates the user's alternative address information.

VendorBankDetails Table

Field Type Required Description
vendor OneToOneField Yes Reference to the associated Vendor model.
bank_name CharField Yes Name of the bank.
account_name CharField Yes Name of the account holder.
account_number CharField Yes (Unique) Bank account number.
branch_name CharField Yes Name of the bank branch.
cheque_book_image ImageField No Image of the cheque book (jpg, png, jpeg).
swift_code CharField No SWIFT code for international transactions.
created_at DateTimeField No Timestamp when the record was created.
updated_at DateTimeField No Timestamp when the record was last updated.

VendorOnBoardingStatus Table

Field Type Required Description
vendor OneToOneField Yes Reference to the associated Vendor model.
status CharField Yes Vendor's onboarding status (unverified, pending, approved, rejected).
comment TextField No Additional comments on vendor approval/rejection.
has_approved BooleanField No Indicates if the vendor is approved.
requested_at DateTimeField No Timestamp when onboarding request was submitted.
approved_at DateTimeField No Timestamp when the vendor was approved.

VendorRole Table

Field Type Required Description
name CharField Yes Name of the vendor role.
permissions ManyToManyField Yes Permissions associated with the role.

VendorAssignedTitle Table

Field Type Required Description
name CharField Yes Name of the assigned title.
description TextField No Description of the assigned title.

VendorRolePermissions Table

Field Type Required Description
user ForeignKey Yes Reference to the User model (sub-vendor).
vendor ForeignKey Yes Reference to the Vendor model (main vendor).
assigned_title ForeignKey Yes Title assigned to the vendor.
role ForeignKey Yes Role assigned to the vendor.
created_by ForeignKey Yes User who created the vendor role permission.
is_active BooleanField No Indicates if the permission is active.
is_deleted BooleanField No Indicates if the permission is deleted.
created_at DateTimeField No Timestamp when the record was created.
updated_at DateTimeField No Timestamp when the record was last updated.