Just an idea: make a column 'order_number' in lines (and in scenes), and
methods 'moveUp', 'moveDown'. Which take care of changing the
'order_numbers'. Generally new lines are added with the highest ordernumber
+ 1, or could be 'inserted' by giving an order number.
Seems easier to me than the prevs and nexts.

just my 2 pence,

TiNo

2007/7/12, Nick Murdoch <[EMAIL PROTECTED]>:

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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to