Modify the models to stop allowing certain fields to be null

This commit is contained in:
Feliciaan De Palmenaer 2015-04-03 14:28:28 +02:00
parent 4c94953059
commit 8a975d5d44

View file

@ -42,7 +42,7 @@ class User(db.Model):
class Location(db.Model): class Location(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120)) name = db.Column(db.String(120), nullable=False)
address = db.Column(db.String(254)) address = db.Column(db.String(254))
website = db.Column(db.String(120)) website = db.Column(db.String(120))
products = db.relationship('Product', backref='location', lazy='dynamic') products = db.relationship('Product', backref='location', lazy='dynamic')
@ -60,8 +60,8 @@ class Location(db.Model):
class Product(db.Model): class Product(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
location_id = db.Column(db.Integer, db.ForeignKey('location.id')) location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
name = db.Column(db.String(120)) name = db.Column(db.String(120), nullable=False)
price = db.Column(db.Integer) price = db.Column(db.Integer, nullable=False)
orderItems = db.relationship('OrderItem', backref='product', lazy='dynamic') orderItems = db.relationship('OrderItem', backref='product', lazy='dynamic')
@ -71,7 +71,7 @@ class Product(db.Model):
self.price = price self.price = price
def __repr__(self): def __repr__(self):
return '%s from %s' % (self.name, self.location) return '%s (€%d)from %s' % (self.name, self.price/100, self.location or 'None')
class Order(db.Model): class Order(db.Model):
@ -90,7 +90,7 @@ class Order(db.Model):
self.stoptime = stoptime self.stoptime = stoptime
def __repr__(self): def __repr__(self):
return 'Order %d @ %s' % (self.id, self.location.name) return 'Order %d @ %s' % (self.id, self.location.name or 'None')
def group_by_user(self): def group_by_user(self):
group = defaultdict(list) group = defaultdict(list)
@ -139,7 +139,7 @@ class OrderItem(db.Model):
return self.name return self.name
def __repr__(self): def __repr__(self):
return 'Order %d: %s wants %s' % (self.order_id, self.get_name(), self.product.name) return 'Order %d: %s wants %s' % (self.order_id or 0, self.get_name(), self.product.name or 'None')
def can_delete(self, order_id, user_id, name): def can_delete(self, order_id, user_id, name):
if int(self.order_id) != int(order_id): if int(self.order_id) != int(order_id):