Accounts — models¶
Responsibilities¶
The accounts app models identity, authentication-adjacent data, workforce profile data, device/session tracking, onboarding through invites, and engineer capability data.
In this project, accounts is responsible for:
- the custom
Usermodel - workforce profile and preferences
- work schedules and weekly hour derivation
- mobile/web device registration and refresh-token session tracking
- invitation-based onboarding for internal and customer users
- skills and user-to-skill assignments
It is not responsible for organization structure itself, but it links closely to orgs, teams, and other domain apps.
Main models¶
User¶
Custom application user model extending Django AbstractUser.
- Fields
- Standard Django auth fields from
AbstractUser ms_oid: external Microsoft/Azure object identifierskills: many-to-many relation toSkillthroughUserSkill- Constraints
- No extra custom DB constraints beyond inherited auth model behavior
- Relationships
- One-to-one with
UserProfile - One-to-one with
UserSettings - One-to-one with
UserWorkSchedule - One-to-many with
Device - One-to-many with invites created via
created_invites - One-to-many with invites accepted via
accepted_invites - One-to-many with invites cancelled via
cancelled_invites - Many-to-many with
SkillthroughUserSkill
The custom user model is the identity anchor for the rest of the app.
UserProfile¶
Operational workforce profile for a user.
- Fields
- Basic identity and display:
display_namephonejob_titleavatarpreferred_namepronouns
- Localization:
timezonelocaleweek_start
- General profile:
biodepartmentlocationemployee_idstart_date
- Employment/workforce:
employment_typeemployment_statusmanager
- Dispatch/planning context:
home_baseprimary_regiontravel_radius_kmhas_company_vehicledriver_license_typecan_travel_internationallyavailability_statusis_dispatchableon_callassignment_notes
- Emergency contact:
emergency_contact_nameemergency_contact_phoneemergency_contact_relation
- Workload:
minimum_weekly_hours
- Constraints
week_startvalidated to be between0and6travel_radius_kmandminimum_weekly_hoursmust be non-negative when set- Relationships
- One-to-one with
User - Optional self-referential workforce manager via
manager -> User
This model is intentionally broader than a simple user profile. It is the workforce identity record used by planning and operations.
Derived behavior¶
effective_minimum_weekly_hours- Uses
minimum_weekly_hourswhen set - Falls back to
UserWorkSchedule.derived_weekly_hours - Falls back to
40.00hours if neither is available
UserWorkSchedule¶
A per-user default work schedule.
- Fields
default_break_minutesupdated_at- Constraints
- One schedule per user
- Relationships
- One-to-one with
User - One-to-many with
UserWorkDay
This model stores the weekly schedule container rather than daily rows directly.
Derived behavior¶
derived_weekly_hours- Sums enabled workdays with valid time ranges
- Subtracts day-specific break or default break
- Returns
Noneif no usable enabled workdays exist
UserWorkDay¶
A single weekday row within a user work schedule.
- Fields
weekdayenabledstart_timeend_timebreak_minutes- Constraints
- Unique per
(schedule, weekday) - Ordered by
weekday - Relationships
- Foreign key to
UserWorkSchedule
This model gives the frontend a stable 7-day schedule payload and supports schedule-derived hour calculations.
UserSettings¶
Frontend-facing UI and preference settings for a user.
- Fields
languagethemegradientcard_stylecard_colorfont_familyfont_scaleaccentdensityreduce_motionpreferencesJSON field- Constraints
- One settings row per user
- Relationships
- One-to-one with
User
This model is used for user-level frontend customization and feature preferences, especially notification preferences.
Skill¶
Canonical skill/certification directory entry.
- Fields
namecategoryis_active- Constraints
nameis unique- Relationships
- Many-to-many with
UserthroughUserSkill
This model is intentionally small and stable so it can serve as a reusable directory across planning and staffing flows.
UserSkill¶
Assignment of a skill to a specific user.
- Fields
userskilllevelvalid_fromvalid_untilnotes- Constraints
- Unique per
(user, skill) - Validation ensures
valid_until >= valid_fromwhen both are set - Relationships
- Foreign key to
User - Foreign key to
Skill
This is the operational relation that stores proficiency and optional certification validity windows.
Device¶
A registered mobile or web client for a user.
- Fields
idUUID primary keydevice_idnameplatformapp_versionlast_seen_atcreated_atpush_providerpush_tokennotifications_enabledtimezone- Constraints
- Unique per
(user, device_id) - Relationships
- Foreign key to
User - One-to-many with
DeviceSession
This model supports device-aware login, push notifications, and session visibility across mobile and web clients.
DeviceSession¶
Refresh-token-backed session tracking bound to a device.
- Fields
idUUID primary keydevicerefresh_jticreated_atrevoked_atipuser_agent- Constraints
refresh_jtiis unique- Relationships
- Foreign key to
Device
This model allows the backend to revoke individual sessions or all sessions for a user while retaining device context.
Invite¶
Invitation used for internal-user or customer-user onboarding.
- Fields
idUUID primary keyinvite_typeemailorgroletokenexpires_atcreated_bycreated_ataccepted_ataccepted_bycancelled_atcancelled_by- Constraints
tokenis unique- Relationships
- Foreign key to
Organization - Foreign key to
Userascreated_by - Foreign key to
Userasaccepted_by - Foreign key to
Userascancelled_by
This model supports onboarding flows for both internal workforce users and customer-portal users.
Derived behavior¶
is_acceptedis_cancelledis_expiredstatuspendingacceptedexpiredcancelledis_valid()- Only
Truewhen status ispending
Relationship overview¶
flowchart TD
User[User]
UserProfile[UserProfile]
UserSettings[UserSettings]
UserWorkSchedule[UserWorkSchedule]
UserWorkDay[UserWorkDay]
Skill[Skill]
UserSkill[UserSkill]
Device[Device]
DeviceSession[DeviceSession]
Invite[Invite]
Organization[Organization]
User -->|1:1| UserProfile
User -->|1:1| UserSettings
User -->|1:1| UserWorkSchedule
UserWorkSchedule -->|1:N| UserWorkDay
User -->|1:N via manager| UserProfile
User -->|1:N| UserSkill
Skill -->|1:N| UserSkill
User -->|1:N| Device
Device -->|1:N| DeviceSession
Organization -->|1:N| Invite
User -->|created_by| Invite
User -->|accepted_by| Invite
User -->|cancelled_by| Invite