Add Entitiy for the Service Object

This commit is contained in:
Joachim Lusiardi 2016-11-01 11:17:54 +01:00
parent 43fa41aace
commit d132dc72de
1 changed files with 23 additions and 0 deletions

View File

@ -63,6 +63,9 @@ class Vehicle(db.Model):
pitstops = db.relationship( pitstops = db.relationship(
'Pitstop' 'Pitstop'
) )
services = db.relationship(
'Service'
)
consumables = db.relationship( consumables = db.relationship(
'Consumable', 'Consumable',
secondary=vehicles_consumables secondary=vehicles_consumables
@ -140,3 +143,23 @@ class Consumable(db.Model):
def __repr__(self): def __repr__(self):
return '<Consumable name="%s" unit="%s" />' % (self.name, self.unit) return '<Consumable name="%s" unit="%s" />' % (self.name, self.unit)
class Service(db.Model):
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.Date)
odometer = db.Column(db.Integer)
vehicle_id = db.Column(db.Integer, db.ForeignKey('vehicle.id'))
costs = db.Column(db.Numeric(10, 2), default=0)
description = db.Column(db.String(4096))
def __init__(self, date, odometer, vehicle_id, costs, description):
self.description = description
self.costs = costs
self.date = date
self.odometer = odometer
self.vehicle_id = vehicle_id
def __repr__(self):
return '<Service odometer="%r" date="%r" vehicle_id="%r" costs="%r" description="%r">' % \
(self.odometer, self.date, self.vehicle_id, self.costs, self.description)