class documentation

class OrderingList(list):

View In Hierarchy

A custom list that manages position information for its children.

The .OrderingList object is normally set up using the .ordering_list factory function, used in conjunction with the _orm.relationship function.

Method __init__ A custom list that manages position information for its children.
Method append Undocumented
Method insert Undocumented
Method pop Undocumented
Method remove Undocumented
Method reorder Synchronize ordering for the entire collection.
Method __delitem__ Undocumented
Method __delslice__ Undocumented
Method __reduce__ Undocumented
Method __setitem__ Undocumented
Method __setslice__ Undocumented
Method ​_get​_order​_value Undocumented
Method ​_order​_entity Undocumented
Method ​_raw​_append Append without any ordering behavior.
Method ​_set​_order​_value Undocumented
Instance Variable ordering​_attr Undocumented
Instance Variable ordering​_func Undocumented
Instance Variable reorder​_on​_append Undocumented
def __init__(self, ordering_attr=None, ordering_func=None, reorder_on_append=False):

A custom list that manages position information for its children.

OrderingList is a collection_class list implementation that syncs position in a Python list with a position attribute on the mapped objects.

This implementation relies on the list starting in the proper order, so be sure to put an order_by on your relationship.

Parameters
ordering​_attrName of the attribute that stores the object's order in the relationship.
ordering​_func

Optional. A function that maps the position in the Python list to a value to store in the ordering_attr. Values returned are usually (but need not be!) integers.

An ordering_func is called with two positional parameters: the index of the element in the list, and the list itself.

If omitted, Python list indexes are used for the attribute values. Two basic pre-built numbering functions are provided in this module: count_from_0 and count_from_1. For more exotic examples like stepped numbering, alphabetical and Fibonacci numbering, see the unit tests.

reorder​_on​_append

Default False. When appending an object with an existing (non-None) ordering value, that value will be left untouched unless reorder_on_append is true. This is an optimization to avoid a variety of dangerous unexpected database writes.

SQLAlchemy will add instances to the list via append() when your object loads. If for some reason the result set from the database skips a step in the ordering (say, row '1' is missing but you get '2', '3', and '4'), reorder_on_append=True would immediately renumber the items to '1', '2', '3'. If you have multiple sessions making changes, any of whom happen to load this collection even in passing, all of the sessions would try to "clean up" the numbering in their commits, possibly causing all but one to fail with a concurrent modification error.

Recommend leaving this with the default of False, and just call reorder() if you're doing append() operations with previously ordered instances or when doing some housekeeping after manual sql operations.

def append(self, entity):

Undocumented

def insert(self, index, entity):

Undocumented

def pop(self, index=-1):

Undocumented

def remove(self, entity):

Undocumented

def reorder(self):

Synchronize ordering for the entire collection.

Sweeps through the list and ensures that each object has accurate ordering information set.

def __delitem__(self, index):

Undocumented

def __delslice__(self, start, end):

Undocumented

def __reduce__(self):

Undocumented

def __setitem__(self, index, entity):

Undocumented

def __setslice__(self, start, end, values):

Undocumented

def _get_order_value(self, entity):

Undocumented

def _order_entity(self, index, entity, reorder=True):

Undocumented

def _raw_append(self, entity):
Append without any ordering behavior.
def _set_order_value(self, entity, value):

Undocumented

ordering_attr =

Undocumented

ordering_func =

Undocumented

reorder_on_append =

Undocumented