Custom model field for sequence-functionality

4 views
Skip to first unread message

mwebs

unread,
May 16, 2008, 7:21:59 AM5/16/08
to Django users
Hello,

what I need is a modelField that provides sequence-functionality for a
model.
This field should have the following features:
- auto_increment when a new instance of the Model is created
- a method move_up() // Increments the sequence of the object
- a method move_down() // Decreases the sequence of the object
- a method sync_order() // Syncronizes all sequences; This sould be
called when a certain model-instance was deleted. The method finds the
"hole" and decreses all other items greater than the one that was
deleted.

My plan was to extend PositiveIntegerField and adding the desired
functionality.
But I could not figure out how to add auto_increment, without falling
back to raw sql.
...and how to add the 3 methods I mentioned above

Here a short example how a Model containing the SequenceField should
be used:

n = News.objects.get(pk = id)
n.moveUp() || n.moveDown()

I am relativley new to Django, and need some help of how to implement
this custom model field.
Thanks, Toni
Reply all
Reply to author
Forward
0 new messages