Initial checkin
This commit is contained in:
19
app/models/shift.py
Normal file
19
app/models/shift.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user