Changeset - 65a43679e76c
[Not reviewed]
0 1 0
Lance Edgar (lance) - 12 years ago 2012-05-02 11:46:49
lance@edbob.org
add Category model
1 file changed with 29 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rattail/model.py
Show inline comments
 
@@ -17,37 +17,39 @@
 
#  FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
 
#  more details.
 
#
 
#  You should have received a copy of the GNU Affero General Public License
 
#  along with Rattail.  If not, see <http://www.gnu.org/licenses/>.
 
#
 
################################################################################
 

	
 
"""
 
``rattail.db.extension.model`` -- Schema Definition
 
"""
 

	
 
from __future__ import absolute_import
 

	
 
import re
 

	
 
from sqlalchemy import (Column, String, Integer, Date, DateTime,
 
                        Boolean, Text, ForeignKey, BigInteger, Numeric)
 
from sqlalchemy.orm import relationship, object_session
 

	
 
import edbob
 
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+)?)\)$')
 

	
 

	
 
class SilColumn(Base):
 
    """
 
    Represents a SIL-compatible column available to the batch system.
 
    """
 

	
 
    __tablename__ = 'sil_columns'
 

	
 
    uuid = uuid_column()
 
@@ -518,35 +520,61 @@ class Department(Base):
 

	
 
    uuid = uuid_column()
 
    number = Column(Integer)
 
    name = Column(String(30))
 

	
 
    def __repr__(self):
 
        return "<Department: %s>" % self.name
 

	
 
    def __str__(self):
 
        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 "<Category: %s, %s>" % (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.
 
    """
 

	
 
    __tablename__ = 'products'
 

	
 
    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):
 
        return "<Product: %s>" % self.description
 

	
 
    def __str__(self):
 
        return str(self.description or '')
0 comments (0 inline, 0 general)