Models¶
The model layer lives in website/models/ and contains SQLAlchemy models only — no business logic.
Models define:
- Database columns and types
- Relationships and foreign keys
- Constraints (unique, not null, etc.)
- Serialization via
SerializableMixin
Overview¶
| Model | Description |
|---|---|
Game |
A tabletop RPG game (one-shot or campaign) |
GameSession |
A scheduled session belonging to a game |
GameEvent |
Audit trail entry for game lifecycle events |
User |
A Discord-authenticated user |
Trophy |
An achievement definition |
UserTrophy |
A trophy awarded to a user |
System |
A tabletop RPG system (e.g. D&D 5e, Pathfinder) |
Channel |
A Discord channel category managed by the app |
SpecialEvent |
A special community event (e.g. Halloween, Christmas) |
Vtt |
A virtual tabletop tool (e.g. Foundry, Roll20) |
API Reference¶
SQLAlchemy model definitions for QuestMaster.
Channel
¶
Bases: Model, SerializableMixin
Discord channel category used for game organization.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Discord channel ID. |
|
type |
Game type this category serves (oneshot or campaign). |
|
size |
Current number of channels in this category. |
Source code in website/models/channel.py
from_dict(data)
classmethod
¶
Game
¶
Bases: Model
Represents a tabletop RPG game (oneshot or campaign).
Source code in website/models/game.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
json
property
¶
Property alias for JSON serialization.
validate_classification(key, value)
¶
Validate the classification JSON against the expected schema.
Source code in website/models/game.py
validate_party_size(key, value)
¶
Ensure party size is at least one.
Source code in website/models/game.py
to_dict(include_relationships=False)
¶
Serialize the Game instance into a Python dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_relationships
|
bool
|
If True, includes nested objects (gm, system, vtt, players, sessions). If False, only includes IDs. |
False
|
Source code in website/models/game.py
to_json(include_relationships=False)
¶
from_dict(data)
classmethod
¶
Create a Game instance from a Python dict. Note: This does not handle relationships (gm, players, sessions, etc.). Those should be set separately after creation.
Source code in website/models/game.py
from_json(data)
classmethod
¶
update_from_dict(data)
¶
Update the Game instance from a dict (in place). Protected fields (id, slug) are excluded from updates. Relationships must be handled separately.
Source code in website/models/game.py
GameEvent
¶
Bases: Model, SerializableMixin
Audit log entry recording an action on a game.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Primary key. |
|
timestamp |
When the event occurred (UTC). |
|
action |
Event action type (create, edit, delete, etc.). |
|
game_id |
Foreign key to the related game. |
|
description |
Optional human-readable description. |
Source code in website/models/game_event.py
from_dict(data)
classmethod
¶
Create a GameEvent instance from a Python dict.
Source code in website/models/game_event.py
GameSession
¶
Bases: Model, SerializableMixin
A scheduled play session belonging to a Game.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Primary key. |
|
game_id |
Foreign key to the parent game. |
|
start |
Session start datetime. |
|
end |
Session end datetime. |
Source code in website/models/game_session.py
SpecialEvent
¶
Bases: Model, SerializableMixin
A themed event that groups related games (e.g. Halloween, conventions).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Primary key. |
|
name |
Unique event name. |
|
emoji |
Optional emoji displayed alongside the event. |
|
color |
Optional color as integer for Discord embeds. |
|
active |
Whether the event is currently running. |
Source code in website/models/special_event.py
System
¶
Bases: Model, SerializableMixin
Represents a game system (e.g., D&D 5e, Call of Cthulhu).
Source code in website/models/system.py
Trophy
¶
Bases: Model, SerializableMixin
Trophy definition (badge template).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Primary key. |
|
name |
Unique trophy name. |
|
unique |
If True, a user can only earn this trophy once. |
|
icon |
Path or URL to the trophy icon. |
Source code in website/models/trophy.py
UserTrophy
¶
Bases: Model, SerializableMixin
Association between a User and a Trophy.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
Foreign key to User. |
|
trophy_id |
Foreign key to Trophy. |
|
quantity |
Number of times this trophy was awarded. |
Source code in website/models/trophy.py
User
¶
Bases: Model, SerializableMixin
Discord-authenticated user.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Discord user ID (17-21 digit string). |
|
name |
Display name (nick or global_name), refreshed from Discord. |
|
username |
Stable Discord username, used for slug generation. |
|
games_gm |
Games where this user is the GM. |
|
trophies |
User trophy associations. |
Source code in website/models/user.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
slug_name
property
¶
Return the stable name for slug generation.
Uses the Discord username (stable, lowercase) when available, falling back to the display name.
display_name
property
¶
Display-friendly name, fetching from Discord if necessary.
trophy_summary
property
¶
Return a list summarizing all trophies of the user.
init_on_load()
¶
Initialize user data after loading from the database.
Skips expensive Discord lookups when in admin context.
Source code in website/models/user.py
refresh_roles()
¶
Refresh role info from Discord (cached for 5 minutes).
Source code in website/models/user.py
to_dict(include_relationships=False)
¶
Serialize the User instance into a Python dict.
Includes dynamic attributes (avatar, roles) not stored in the database.
Source code in website/models/user.py
from_dict(data)
classmethod
¶
Create a User object from a dictionary.
Expected keys: 'id' (required), 'name' (optional). Additional keys (avatar/is_gm/is_admin/is_player) will be set as attributes on the created instance if present.
Source code in website/models/user.py
from_json(data)
classmethod
¶
update_from_dict(data)
¶
Vtt
¶
Bases: Model, SerializableMixin
A virtual tabletop platform (e.g. Foundry VTT, Roll20).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Primary key. |
|
name |
Unique VTT name. |
|
icon |
Path or URL to the VTT icon. |