Sample of model for use with SelectField

Sample of model for use with SelectField
mail@pastecode.io avatar
unknown
python
a year ago
1.2 kB
2
Indexable
Never
class BrewType(enum.Enum):
    ESPRESSO = 1
    V60 = 2
    AEROPRESS = 3
    MOKAPOT = 4
    FRENCH_PRESS = 5
    CHEMEX = 6
    KALITA = 7
    SIPHON = 8
    CUPPING = 9
    TURKISH = 10


class Record(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_posted = db.Column(db.TIMESTAMP(timezone=True), nullable=False, default=datetime.now)
    taster_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    taster = db.relationship('User', foreign_keys=[taster_id], lazy=True)
    coffee_bean = db.Column(db.String(50), nullable=False)
    roast_date = db.Column(db.Date, nullable=True)
    brew_type = db.Column(db.Enum(BrewType), nullable=False)
    grind_setting = db.Column(db.Numeric(4, 2), nullable=True)
    dose_size = db.Column(db.Numeric(4, 1), nullable=True)
    output_size = db.Column(db.Numeric(4, 1), nullable=True)
    brew_time = db.Column(db.Integer, nullable=True)
    tasting_notes = db.Column(db.String(500), nullable=True)

    def __repr__(self):
        return f'Record("{self.date_posted}", "{self.taster}", "{self.coffee_bean}", "{self.brew_type}", ' \
               f'{self.grind_setting}, {self.dose_size}, {self.output_size} )'