MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / ordering_list

Function ordering_list

lib/sqlalchemy/ext/orderinglist.py:155–200  ·  view source on GitHub ↗

Prepares an :class:`OrderingList` factory for use in mapper definitions. Returns an object suitable for use as an argument to a Mapper relationship's ``collection_class`` option. e.g.:: from sqlalchemy.ext.orderinglist import ordering_list class Slide(Base):

(
    attr: str,
    count_from: Optional[int] = None,
    ordering_func: Optional[OrderingFunc[_T]] = None,
    reorder_on_append: bool = False,
)

Source from the content-addressed store, hash-verified

153
154
155def ordering_list(
156 attr: str,
157 count_from: Optional[int] = None,
158 ordering_func: Optional[OrderingFunc[_T]] = None,
159 reorder_on_append: bool = False,
160) -> Callable[[], OrderingList[_T]]:
161 """Prepares an :class:`OrderingList` factory for use in mapper definitions.
162
163 Returns an object suitable for use as an argument to a Mapper
164 relationship's ``collection_class`` option. e.g.::
165
166 from sqlalchemy.ext.orderinglist import ordering_list
167
168
169 class Slide(Base):
170 __tablename__ = "slide"
171
172 id = Column(Integer, primary_key=True)
173 name = Column(String)
174
175 bullets = relationship(
176 "Bullet",
177 order_by="Bullet.position",
178 collection_class=ordering_list("position"),
179 )
180
181 :param attr:
182 Name of the mapped attribute to use for storage and retrieval of
183 ordering information
184
185 :param count_from:
186 Set up an integer-based ordering, starting at ``count_from``. For
187 example, ``ordering_list('pos', count_from=1)`` would create a 1-based
188 list in SQL, storing the value in the 'pos' column. Ignored if
189 ``ordering_func`` is supplied.
190
191 Additional arguments are passed to the :class:`.OrderingList` constructor.
192
193 """
194
195 kw = _unsugar_count_from(
196 count_from=count_from,
197 ordering_func=ordering_func,
198 reorder_on_append=reorder_on_append,
199 )
200 return lambda: OrderingList(attr, **kw)
201
202
203# Ordering utility functions

Callers 8

test_append_reorderMethod · 0.90
test_insertMethod · 0.90
test_sliceMethod · 0.90
test_replaceMethod · 0.90
test_replace_twoMethod · 0.90
test_funky_orderingMethod · 0.90

Calls 2

_unsugar_count_fromFunction · 0.85
OrderingListClass · 0.85

Tested by 7

test_append_reorderMethod · 0.72
test_insertMethod · 0.72
test_sliceMethod · 0.72
test_replaceMethod · 0.72
test_replace_twoMethod · 0.72
test_funky_orderingMethod · 0.72