Is it possible to combine SQLObject Versioning with a SQLRelatedJoin?

Here's what I'm trying to do:  I have a many-to-many relationship 
between two classes, "Asset" and "Cart".  A Cart can have a bunch of 
Assets, and Assets can belong to more than one cart.

I'd like to be able to version changes to the assets that are in the 
cart (i.e. the cart.assets field) as well as the other

Here's a simplified version of what I'm doing:

#!/usr/bin/env python

import os, time, datetime
from sqlobject import *
from sqlobject.versioning import Versioning

class Asset(SQLObject):
     name = StringCol(unique=True, length=255)
     author = StringCol(length=20, default=os.getenv('USER'))
     date = DateTimeCol(default=DateTimeCol.now)
     notes = StringCol(default='')
     savedcarts = SQLRelatedJoin('Cart')


class Cart(SQLObject):
     """ A saved list of AssetItems. Usually created in RepoBrowse. """
     name = StringCol(unique=True, length=255)
     author = StringCol(length=20, default=os.getenv('USER'))
     date = DateTimeCol(default=DateTimeCol.now)
     notes = StringCol(default='')
     assets = SQLRelatedJoin("Asset", addRemoveName="Asset")

     versions = Versioning()

     def dumpVersions(self):
         for i, vers in enumerate(self.versions):
             allAssetNames = [ass.name for ass in vers.assets]
             print "#%d %s %-40.40s %s     Assets: %s"%(i, vers.name, 
vers.notes, vers.date, ','.join(allAssetNames))


if __name__ == '__main__':
     # Make DB
     dbname = os.path.abspath("joinV.sq3")
     os.remove(dbname)
     dburl = 'sqlite://%s'%dbname
     connection = connectionForURI(dburl)
     sqlhub.processConnection = connection

     Asset.createTable(ifNotExists=True)
     Cart.createTable(ifNotExists=True)

     # Make some assets
     assFoo = Asset(name="Foo")
     assBar = Asset(name="Bar")
     assBaz = Asset(name="Baz")
     assAck = Asset(name="Ack")

     # Make a cart
     cart = Cart(name="Savedcart1")

     for i, ass in enumerate([assFoo, assBar, assBaz, assAck]):
         cart.addAsset(ass)
         cart.notes='submission %d--added "%s"'%(i, ass.name)

     cart.dumpVersions()



This outputs:

#0 Savedcart1 2015-06-08 16:36:59     Assets: Foo,Bar,Baz,Ack
#1 Savedcart1 submission 0--added "Foo" 2015-06-08 16:36:59     Assets: 
Foo,Bar,Baz,Ack
#2 Savedcart1 submission 1--added "Bar" 2015-06-08 16:36:59     Assets: 
Foo,Bar,Baz,Ack
#3 Savedcart1 submission 2--added "Baz" 2015-06-08 16:36:59     Assets: 
Foo,Bar,Baz,Ack

What I'd like to see is #0 have vers.assets only contain "Foo", #1 have 
only "Foo" and "Bar", etc.
Is this possible with SQLObject's versioning?

Thanks much!
Alex Seiden

p.s. I'm using Linux (CentOS 6.6), python 2.7, and SQLObject 1.6.  I 
would update to a more recent SQLObject if it would matter, but I didn't 
see anything in the release notes that seemed relevant.  And FWIW, my 
'real' app uses mysql, but sqlite was easier for the example.


------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to