class Subbrand(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False) def __init__(self, name): self.name = name def __repr__(self): return f'<id {self.id}>' def serialize(self): return {'id': self.id, 'name': self.name}
class Detail(db.Model): id = db.Column(db.Integer, primary_key=True) belt = db.Column(db.SmallInteger, nullable=True) alcohol = db.Column(db.Boolean, nullable=True) amount = db.Column(db.Integer, nullable=True) injured = db.Column(db.String(10), nullable=True) consec = db.Column(db.Integer, nullable=True) conse_g = db.Column(db.Integer, nullable=True) conse_m = db.Column(db.Integer, nullable=True) conse_sem = db.Column(db.Integer, nullable=False) _merge = db.Column(db.String(15), nullable=True) accident = db.relationship('Accident', uselist=False) def __init__(self, belt, alcohol, amount, injured, consec, conse_g, conse_m, conse_sem, _merge): self.belt = belt self.alcohol = alcohol self.amount = amount self.injured = injured self.consec = consec self.conse_g = conse_g self.conse_m = conse_m self.conse_sem = conse_sem self._merge = _merge def __repr__(self): return f'<id {self.id}>' def serialize(self): return { 'id': self.id, 'belt': self.belt, 'amount': self.amount, 'injured': self.injured, 'consec': self.consec, 'conse_g': self.conse_g, 'conse_m': self.conse_m, 'conse_sem': self.conse_sem, '_merge': self._merge }
class Car(db.Model): id = db.Column(db.Integer, primary_key=True) model = db.Column(db.String(10), nullable=True) brand_id = db.Column(db.Integer, db.ForeignKey('brand.id'), nullable=True) brand = db.relationship('Brand', foreign_keys=[brand_id]) subbrand_id = db.Column(db.Integer, db.ForeignKey('subbrand.id'), nullable=True) subbrand = db.relationship('Subbrand', foreign_keys=[subbrand_id]) car_type_id = db.Column(db.Integer, db.ForeignKey('car_type.id'), nullable=True) car_type = db.relationship('Car_type', foreign_keys=[car_type_id]) accident = db.relationship('Accident', uselist=False) def __init__(self, model, brand_id, subbrand_id, car_type_id): self.model = model self.brand_id = brand_id self.subbrand_id = subbrand_id self.car_type_id = car_type_id def __repr__(self): return f'<id {self.id}>' def serialize(self): return { 'id': self.id, 'model': self.model, 'brand_id': self.brand_id, 'subbrand_id': self.subbrand_id, 'car_type_id': self.car_type_id }