Skip to main content

Overview

The Artist model represents a tattoo artist in the studio with commission rate configuration and relationships to sessions and portfolio items.

Model Definition

from sqlalchemy import String, Float, Boolean
from sqlalchemy.orm import Mapped, mapped_column, relationship

class Artist(Base):
    __tablename__ = "artists"

Fields

Primary Key

id
int
required
Unique identifier for the artist (auto-increment)

Artist Information

name
str
required
Artist’s name or stage nameLength: Maximum 120 charactersIndexed: Yes, for fast lookups
rate_commission
float
default:"0.50"
Commission rate for the artist (0.0 to 1.0)Default: 0.50 (50% commission)Example: 0.50 means the artist receives 50% of session revenue
active
bool
default:"true"
Whether the artist is currently active in the studio

Relationships

sessions
List[TattooSession]
List of all tattoo sessions assigned to this artistRelationship: One-to-Many with TattooSessionBack Populates: artist on TattooSession model
portfolio_items
List[PortfolioItem]
List of portfolio items (images) associated with this artistRelationship: One-to-Many with PortfolioItemCascade: all, delete-orphan - portfolio items are deleted when artist is deletedBack Populates: artist on PortfolioItem model
preferred_clients
List[Client]
List of clients who have this artist as their preferred artistRelationship: Backref from Client.preferred_artistForeign Key: Client.preferred_artist_id → Artist.id

Database Schema

CREATE TABLE artists (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name VARCHAR(120) NOT NULL,
    rate_commission FLOAT DEFAULT 0.50,
    active BOOLEAN DEFAULT 1
);

CREATE INDEX ix_artists_name ON artists(name);

Usage Examples

Create a New Artist

from data.models.artist import Artist

# Create artist with default commission rate
artist = Artist(
    name="Luna Martinez",
    active=True
)
db.add(artist)
db.commit()

# Create artist with custom commission rate
artist = Artist(
    name="Alex Chen",
    rate_commission=0.60,  # 60% commission
    active=True
)
db.add(artist)
db.commit()

Query Artist with Sessions

from data.models.artist import Artist
from sqlalchemy.orm import Session

# Get artist with all sessions
artist = db.query(Artist).filter(Artist.id == 1).first()

print(f"Artist: {artist.name}")
print(f"Commission Rate: {artist.rate_commission * 100}%")
print(f"Total Sessions: {len(artist.sessions)}")
print(f"Portfolio Items: {len(artist.portfolio_items)}")

# Calculate total revenue
total_revenue = sum(session.price for session in artist.sessions)
artist_earnings = total_revenue * artist.rate_commission

print(f"Total Revenue: ${total_revenue:.2f}")
print(f"Artist Earnings: ${artist_earnings:.2f}")

Get Active Artists

# Query only active artists
active_artists = db.query(Artist).filter(Artist.active == True).all()

for artist in active_artists:
    print(f"{artist.name} - {artist.rate_commission * 100}% commission")

Update Commission Rate

# Update an artist's commission rate
artist = db.query(Artist).filter(Artist.id == 1).first()
artist.rate_commission = 0.55  # Change to 55%
db.commit()

Commission Rate Details

The rate_commission field determines how revenue is split between the artist and the studio:
  • Value Range: 0.0 to 1.0 (representing 0% to 100%)
  • Default: 0.50 (50/50 split)
  • Common Values:
    • 0.40 = 40% to artist, 60% to studio
    • 0.50 = 50% to artist, 50% to studio
    • 0.60 = 60% to artist, 40% to studio
The commission rate is used in transaction calculations and reporting. Individual sessions can override this rate using TattooSession.commission_override.

Notes

  • Artists can be deactivated using the active flag without deleting their records
  • The name field is indexed for fast searches and lookups
  • Commission rates are stored as decimals (0.50 = 50%)
  • Deleting an artist will cascade delete all their portfolio items
  • Sessions have RESTRICT on delete, preventing artist deletion if they have sessions
  • Location in codebase: data/models/artist.py:5

Build docs developers (and LLMs) love