Login

Tag "ordered"

Snippet List

SortableModel - abstract model class for sortable records

If you have a model that has an "ordering" column, and you want to be able to re-position records (eg, order items by priority), this base class should make it fairly easy. To use it, you extend your model using this abstract class, then hook up the pre_save event to the pre_save event of the base class, and you're good to go. Whenever you save an item, it ensures that it has a valid "order" number. The meat of this class is the "move()" method. Just call instance.move(number) where instance is your model instance, and this class will do all the logic necessary to shift around the order numbers for you.

  • sort
  • order
  • sortable
  • orderable
  • sorted
  • ordered
Read More

1 snippet posted so far.