53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
"""Magic: The Gathering legality models."""
|
|
|
|
from odoo import fields, models
|
|
|
|
LEGALITY_SELECTION = [
|
|
("legal", "Legal"),
|
|
("not_legal", "Not Legal"),
|
|
("restricted", "Restricted"),
|
|
("banned", "Banned"),
|
|
]
|
|
|
|
|
|
class MvdTcgMtgCardLegality(models.Model):
|
|
"""Store one legality status per MTG card and constructed format."""
|
|
|
|
_name = "mvd.tcg.mtg.card.legality"
|
|
_description = "MTG Card Legality"
|
|
_order = "format_sequence, id"
|
|
|
|
card_id = fields.Many2one(
|
|
"mvd.tcg.card",
|
|
required=True,
|
|
index=True,
|
|
ondelete="cascade",
|
|
)
|
|
format_id = fields.Many2one(
|
|
"mvd.tcg.mtg.format",
|
|
required=True,
|
|
index=True,
|
|
ondelete="restrict",
|
|
)
|
|
format_code = fields.Char(
|
|
related="format_id.code",
|
|
store=True,
|
|
index=True,
|
|
)
|
|
format_sequence = fields.Integer(
|
|
related="format_id.sequence",
|
|
store=True,
|
|
index=True,
|
|
)
|
|
status = fields.Selection(
|
|
selection=LEGALITY_SELECTION,
|
|
required=True,
|
|
default="not_legal",
|
|
index=True,
|
|
)
|
|
|
|
_card_format_unique = models.Constraint(
|
|
"UNIQUE (card_id, format_id)",
|
|
"The MTG legality format must be unique per card.",
|
|
)
|