Does django has something like the rails ActiveRecord acts_as_list?

For those who don't know what acts_as_list is, it gives you the api
for dealing with an ordered list of objects.  For example, think if
was modeling a book.  I would have a Book object with a one to of a
simple Netflix queue.  You might have a database table like this:

class Book(models.Model):
    title = models.CharField(maxlength=50)

class Chapter(models.Model):
    book = models.ForeignKey(Book)
    position = models.IntegerField
    title = models.CharField(maxlength=50)

Now, it would be nice if I could do something like this:

#Create the book
book = Book(title="Dive Into Python")

#Create a chapter, have it automatically set the position
#based on the current number of chapters
chapter = Chapter(book=b, title="Installing Python")

#If that's not possible, how would you do it manually, like this?
chapter = Chapter(book=b, title="Installing Python",
position=book.chapter_set.count()+1)

#Anyway, save the chapter
chapter.save()

#Make another chapterm.  By the way, I'm a Java programmer, new to Python,
#will this work like I think?  Does chapter now point to a new
instance of Chapter,
#and changes after this line would have no effect
#on the chapter I created in the previous line?
chapter = Chapter(book=b, title="Your First Python Program",
position=book.chapter_set.count()+1)

#Now I realize the chapters are out of order, so I want to re-order them
#It would be nice if this method would set the value of the current
#chapter's position to 1, and the value of the other chapter's position to 2
chapter.move_lower

Here are some links to acts_as_list:
http://rubyonrails.org/api/classes/ActiveRecord/Acts/List/InstanceMethods.html
http://brianfox.wordpress.com/2006/08/08/acts_as_list-in-ruby-on-rails/

Here are the methods with a description:
decrement_position     Moves an item position down one
first?                          Returns true if item is first in list,
false if not higher_item Returns the record immediately  above the
current record
in_list?                       Returns true if item is in list, false if not
increment_position      Moves an item up one position
insert_at(position = 1) Adds an item to the list in a specific position
last?                          Returns true if item is last in list,
false if not
lower_item                 Returns the record immediately below the
current record
move_higher              Moves an item up one position
move_lower               Moves an item down one position
move_to_bottom       Moves an item to the bottom of the list
move_to_top             Moves an item to the top of the list
remove_from_list       Removes an item from the list

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to