Overview
The domain models represent the core business entities in the IMDb scraper. Each model includes built-in validation to ensure data integrity.Movie
Represents a movie entity with comprehensive metadata and validation.Class Definition
domain/models/movie.py:8-20
Fields
Database-assigned unique identifier.
None for new movies.IMDb unique identifier (e.g.,
tt0111161). Must match pattern ^tt\d{7,}$.Movie title. Cannot be empty after stripping whitespace.
Release year. Must be between 1888 and 2030.
IMDb rating. Must be between 0.0 and 10.0.
Runtime in minutes. Must be positive if provided.
Metascore rating. Must be between 0 and 100 if provided.
List of actors appearing in the movie. Defaults to empty list.
Validation
The__post_init__ method performs automatic validation:
- Strips whitespace from
titleandimdb_id - Validates IMDb ID format with regex
^tt\d{7,}$ - Ensures title is not empty
- Validates year range (1888-2030)
- Validates rating range (0.0-10.0)
- Validates duration is positive
- Validates metascore range (0-100)
domain/models/movie.py:22-42
Example
Actor
Represents an actor entity with name validation.Class Definition
domain/models/actor.py:6-12
Fields
Database-assigned unique identifier.
None for new actors.Actor’s full name. Cannot be empty after stripping whitespace.
Validation
The__post_init__ method performs automatic validation:
- Strips whitespace from
name - Ensures name is not empty
domain/models/actor.py:14-18
Example
MovieActor
Represents the many-to-many relationship between movies and actors.Class Definition
domain/models/movie_actor.py:5-11
Fields
Foreign key reference to a movie. Must be a positive integer.
Foreign key reference to an actor. Must be a positive integer.
Validation
The__post_init__ method validates both IDs:
- Ensures
movie_idis a positive integer - Ensures
actor_idis a positive integer
domain/models/movie_actor.py:13-19
Example
Error Handling
All models raiseValueError when validation fails: