Files
electric-vehicle-battery-ch…/app/models/shift.py
2023-05-18 18:21:00 -04:00

19 lines
732 B
Python

from app.extensions import db, ma
from flask_marshmallow import fields
class Shift(db.Model):
id = db.Column(db.Integer, primary_key=True)
battery_changes = db.relationship('BatteryChange',
backref='battery_changes',
order_by='BatteryChange.order')
class ShiftSchema(ma.Schema):
battery_changes = ma.Nested('BatteryChangeSchema', many=True)
all_completed = fields.fields.Method('get_all_completed')
class Meta:
model=Shift
include_fk=True
fields = ("id", "battery_changes", "all_completed")
def get_all_completed(self, obj):
return all(change.completed == True for change in obj.battery_changes)