diff --git a/rattail/model.py b/rattail/model.py index 912f94b0718ec87c0620705db2b86f2fe06189aa..a19397753a56caa5cf67b0052b39fbc60feb1f9f 100644 --- a/rattail/model.py +++ b/rattail/model.py @@ -26,6 +26,8 @@ ``rattail.db.extension.model`` -- Schema Definition """ +from __future__ import absolute_import + import re from sqlalchemy import (Column, String, Integer, Date, DateTime, @@ -38,7 +40,7 @@ from edbob.db.model import Base, uuid_column __all__ = ['SilColumn', 'BatchDictionaryColumn', 'BatchDictionary', 'BatchTerminalColumn', 'BatchTerminal', 'BatchColumn', - 'Batch', 'Brand', 'Department', 'Product'] + 'Batch', 'Brand', 'Department', 'Category', 'Product'] sil_type_pattern = re.compile(r'^(CHAR|NUMBER)\((\d+(?:\,\d+)?)\)$') @@ -527,6 +529,30 @@ class Department(Base): return str(self.name or '') +class Category(Base): + """ + Represents an organizational category for products. + """ + + __tablename__ = 'categories' + + uuid = uuid_column() + number = Column(Integer) + name = Column(String(50)) + department_uuid = Column(String(32), ForeignKey('departments.uuid')) + + department = relationship(Department) + + def __repr__(self): + return "" % (self.number, self.name) + + def __str__(self): + return str(self.name or '') + + def __unicode__(self): + return unicode(self.name or '') + + class Product(Base): """ Represents a product for sale and/or purchase. @@ -537,12 +563,14 @@ class Product(Base): uuid = uuid_column() upc = Column(BigInteger) department_uuid = Column(String(32), ForeignKey('departments.uuid')) + category_uuid = Column(String(32), ForeignKey('categories.uuid')) brand_uuid = Column(String(32), ForeignKey('brands.uuid')) description = Column(String(60)) description2 = Column(String(60)) size = Column(String(30)) department = relationship(Department) + category = relationship(Category) brand = relationship(Brand) def __repr__(self):