Overview
TheTattooSession model represents a tattoo appointment or session, linking clients and artists with scheduling information, pricing, payment tracking, and status management.
Model Definition
Fields
Primary Key
Unique identifier for the session (auto-increment)
Relationships
Foreign key reference to the clientForeign Key: clients.idOn Delete: CASCADE (session deleted when client is deleted)Indexed: Yes
Foreign key reference to the artistForeign Key: artists.idOn Delete: RESTRICT (prevents artist deletion if they have sessions)Indexed: Yes
Scheduling
Session start date and timeIndexed: Yes, for calendar queries
Session end date and timeIndexed: Yes, for calendar queries
Session Details
Current status of the sessionType: EnumValid Values:
- “Activa” - Active/ongoing session
- “Completada” - Completed session
- “En espera” - Waiting/scheduled
- “Cancelada” - Cancelled session
Total price for the session
Additional notes about the sessionType: Text (unlimited length)Nullable: True
Commission
Optional commission rate override for this specific sessionNullable: TrueUsage: If set, overrides the artist’s default
rate_commissionExample: 0.55 = 55% commission for this session onlyRelationship Objects
The Client object for this sessionRelationship: Many-to-OneBack Populates:
sessions on Client modelThe Artist object for this sessionRelationship: Many-to-OneBack Populates:
sessions on Artist modelList of all payment transactions for this sessionRelationship: One-to-Many with TransactionCascade:
all, delete-orphan - transactions deleted when session is deletedOrdered By: Transaction.date (chronological order)Computed Properties
transaction
The most recent transaction for this sessionNote: Legacy property for backward compatibility. Use
transactions list for full payment history.total_paid
Total amount paid across all transactions (excluding deleted transactions)Calculation: Sums all
transaction.amount where deleted_flag is FalseExample: If transactions are [100.0, 50.0, 25.0], returns 175.0balance
Remaining balance to be paidCalculation:
max(0.0, price - total_paid)Example: If price is 500.0 and total_paid is 300.0, returns 200.0Note: Never negative (minimum is 0.0)Database Schema
Usage Examples
Create a New Session
Query Sessions with Payment Info
Get Sessions by Date Range
Get Artist’s Sessions
Update Session Status
Calculate Commission
Status Workflow
Typical session status progression:- En espera - Session is scheduled but hasn’t started
- Activa - Session is currently in progress
- Completada - Session finished successfully
- Cancelada - Session was cancelled
Payment Tracking
The session tracks payments through thetransactions relationship:
- Multiple payments: A session can have multiple transactions (deposits, installments)
- total_paid: Automatically calculated from all non-deleted transactions
- balance: Shows remaining amount (price - total_paid)
- Full payment: When
balanceequals 0.0
Composite Index
The model includes a composite index for efficient artist schedule queries:Notes
- Sessions cascade delete when the client is deleted (ON DELETE CASCADE)
- Artists cannot be deleted if they have sessions (ON DELETE RESTRICT)
- The
commission_overrideallows per-session commission rates - Use
total_paidandbalanceproperties instead of calculating manually - All datetime fields should include timezone information in production
- Location in codebase:
data/models/session_tattoo.py:14