diff options
author | 2010-08-01 17:35:55 +0300 | |
---|---|---|
committer | 2010-08-01 17:35:55 +0300 | |
commit | 44710dbfe031bd895e3e42f33e752cfa327cbcff (patch) | |
tree | 8e0a38ca8d8d9e687780c3426b6d3269487fb77b | |
parent | Update Category and Package model, rework unittests (diff) | |
download | gsoc2010-grumpy-44710dbfe031bd895e3e42f33e752cfa327cbcff.tar.gz gsoc2010-grumpy-44710dbfe031bd895e3e42f33e752cfa327cbcff.tar.bz2 gsoc2010-grumpy-44710dbfe031bd895e3e42f33e752cfa327cbcff.zip |
Use column_mapped_collection for Category.packages
-rw-r--r-- | grumpy/models.py | 4 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 9 |
2 files changed, 8 insertions, 5 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index c3f0b71..85683fb 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -13,6 +13,7 @@ from . import app from datetime import datetime from flaskext.sqlalchemy import SQLAlchemy from sqlalchemy.sql import func +from sqlalchemy.orm.collections import column_mapped_collection import json, random, string, time @@ -36,7 +37,8 @@ class Category(db.Model): category = db.Column('category', db.String, nullable=False, unique=True) packages = db.relationship("Package", backref='category', \ - cascade='all, delete, delete-orphan') + cascade='all, delete, delete-orphan', \ + collection_class=column_mapped_collection(db.text('packages.pkg_cat'))) def __init__(self, category): self.category = category diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index a6f8b3b..fc6a8d8 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -48,10 +48,11 @@ class PkgModelTestCase(GrumpyTestCase): assert Category.query.count() == 2 ## Create and test packages - c[0].packages.append(Package(p1)) - # TODO: Need to figure out a convenience method... - #c[0].packages.append(Package(p2)) - c[1].packages.append(Package(p3)) + for p in (p1, p2): + x = Package(p) + c[0].packages[x.pkg_cat] = x + x = Package(p3) + c[1].packages[x.pkg_cat] = x self.db.session.commit() assert Package.query.count() == 2 |