For completeness, let me assume you have more than one playlist:

db.define_table('playlist',Field('playlist_name',),
                            Field('title','string'),
                            Field('start_time','integer'),
                            Field('duration','integer')
                            )

def insert_after(record, new_record):
      query = db.playlist.playlist_title==record.playlist_title
      if record: query &= (db.playlist.start_time>record.start_time)
      
db(query).update(start_time=db.playlist.start_time+new_record['duration'])
      db.playlist.insert(**new_record)

insert_after(db.playlist(nnn), {'playlist_title':..., 'title':..., 
start_time:..., duration:...})

On Saturday, 18 January 2014 15:19:38 UTC-6, Jaime Sempere wrote:
>
>
> Hi everyone,
>
> Although I have used database serveral times, I have not done anything 
> beyond very basic, so I am wondering what would be the best practice for 
> this case:
>
>
> I have a database table for storing a 'real-time' playlist of songs like 
> this:
>
> db.define_table('playlist',Field('title','string'),
>                             Field('start_time','integer'),
>                             Field('duration','integer')
>                             )
>
> For example:          
>
>                   row 0:       Title:    Imagine        ;       start 
> time: 0:00        ; duration 3:43  
>                   row 1:       Title:    My way        ;       start 
>  time: 3:43       ; duration  4:00
>                   row 2:       Title:    I feel good    ;   start  time: 
> 7:43       ; duration  4:00
>
>                              
> As you see, start time of every song stands for the 'real time' at which 
> the song will be played.
>
> What I need to know is the best approach in web2py for insert a new row in 
> the middle of the table and update songs below. 
>
> Example, say that I add, "my song" between 0 and 1:
>
>                   row 0:       Title:    Imagine        ;       start 
> time: 0:00        ; duration 3:43  
>                   row 1:       Title:    My Song        ;       start 
> time: 3:43        ; duration 3:00  
>                   row 2:       Title:    My way        ;       start 
>  time: 7:43       ; duration  4:00
>                   row 3:       Title:    I feel good    ;   start  time: 
> 11:43       ; duration  4:00
>
> I need to update and change start times for old rows 1 and 2...
>
> I have never face this kind of problem but I have seen that in a SQL 
> triggers could do the update. How could I approach this problem in web2py?
>
> Thanks in advance
>
> PS: I forgot to say, this is only an example, the number of total rows in 
> my database could be large (say from 1.000 to 10.000).
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to