[SQLObject] Problem with re-ordering rows.
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Nick M. <nmu...@lo...> - 2007-07-12 10:49:14
|
Hi all, I'm attempting to write an app that will let me create a set of Acts, where each Act can contain some Scenes, and each Scene can contain some Lines. Simple enough, but I also want to be able to rearrange the Lines in a Scene (and, ideally, the Scenes in an Act) To me it seems like I need something along the lines of a linked list to be able to do that, however I've come a bit unstuck trying to implement this into SQLObject classes. I've come up with the following so far, but I'm having trouble assigning 'prev' and 'next' to any Lines I create: class Act(SQLObject): owner = ForeignKey('Play') title = UnicodeCol() scenes = MultipleJoin('Scene', joinColumn="owner_id") created = DateTimeCol(default=datetime.now) class Scene(SQLObject): owner = ForeignKey('Act') title = UnicodeCol() lines = MultipleJoin('Line', joinColumn="owner_id") created = DateTimeCol(default=datetime.now) prev = SingleJoin('Scene') next = SingleJoin('Scene') class Line(SQLObject): owner = ForeignKey('Scene') text = UnicodeCol() prev = SingleJoin('Line', addRemoveName='Prev') next = SingleJoin('Line', addRemoveName='Next') created = DateTimeCol(default=datetime.now) >>> play = Play(owner=me, title="moo", description="moo") >>> act = Act(owner=play, title="Act I") >>> scene = Scene(owner=act, title="Scene 1") >>> line1 = Line(owner=scene, text="moo") >>> line2 = Line(owner=scene, text="moo2") >>> line1.addNext(line2) Traceback (most recent call last): File "<console>", line 1, in ? AttributeError: 'Line' object has no attribute 'addNext' >>> line1.next = line2 Traceback (most recent call last): File "<console>", line 1, in ? AttributeError: can't set attribute Is there a better way to go about doing this? Thanks, Nick Murdoch |