public
Description: A Django field for custom model ordering.
Homepage: http://code.google.com/p/django-positions/
Clone URL: git://github.com/jpwatts/django-positions.git
name age message
file .gitignore Sat Nov 14 20:31:25 -0800 2009 some additional tests [Jacob Smullyan]
file AUTHORS Mon Nov 16 08:52:44 -0800 2009 Updated AUTHORS file. [jpwatts]
file LICENSE Mon Jul 14 23:42:47 -0700 2008 Added LICENSE file. [jpwatts]
file README Mon Nov 16 08:59:09 -0800 2009 Updated docs for unique_for_fields change. [jpwatts]
directory positions/ Mon Nov 16 08:50:55 -0800 2009 Re-added unique_for_field argument for backward... [jpwatts]
file setup.py Mon Nov 16 08:59:53 -0800 2009 Increased version number. [jpwatts]
README
================
Django Positions
================

This module provides ``PositionField``, a model field for Django_ that allows
instances of a model to be sorted by a user-specified position.  Conceptually,
the field works like a list index: when the position of one item is changed, the
positions of other items in the collection are updated in response.


Usage
-----

Add a ``PositionField`` to your model; that's just about it.

If you want to work with all instances of the model as a single collection,
there's nothing else required.  To create collections based on one or more
fields on the model, set ``unique_for_fields`` to a list containing the names
of the fields.

The apps in ``positions.examples`` demonstrate the ``PositionField`` API.


Indices
~~~~~~~

In general, the value assigned to a ``PositionField`` will be handled like a
list index, to include negative values.  Setting the position to ``-2`` will
cause the item to be moved to the second position from the end of collection --
unless, of course, the collection has fewer than two elements.

Behavior varies from standard list indices when values greater than or less than
the maximum or minimum positions are used.  In those cases, the value is handled
as being the same as the maximum or minimum position, respectively.  ``None`` is
also a special case that will cause an item to be moved to the last position in
its collection.


Limitations
-----------

* Unique constraints can't be applied to ``PositionField`` because they break
  the ability to update other items in a collection all at once.  This one was
  a bit painful, because setting the constraint is probably the right thing to
  do from a database consistency perspective, but the overhead in additional
  queries was too much to bear.

* After a position has been updated, other members of the collection are updated
  using a single SQL ``UPDATE`` statement, this means the ``save`` method of the
  other instances won't be called.

.. _`Django`: http://www.djangoproject.com/