Skip to main content

Django field to help arrange model instances in an ordered fashion

Project description

=============================
django-ordered-field
=============================

.. image:: https://badge.fury.io/py/django-ordered-field.svg
:target: https://badge.fury.io/py/django-ordered-field

.. image:: https://travis-ci.org/kimgea/django-ordered-field.svg?branch=master
:target: https://travis-ci.org/kimgea/django-ordered-field

.. image:: https://codecov.io/gh/kimgea/django-ordered-field/branch/master/graph/badge.svg
:target: https://codecov.io/gh/kimgea/django-ordered-field

A django field to make it easy to order your model instances. If you have made an ordered list and you change the position of the list item instance then all the other list iteminstances belonging to that list has their position automatically updated to keep the list ordered without holes and list items with duplicate positions.
``OrderedField field`` is a global ordering field for the entire table.
``OrderedCollectionField`` order instances with respect to one or more other fields on the instance.


Requires
--------
* python>=3.6
* django>=2.0

Documentation
-------------

The full documentation is at https://django-ordered-field.readthedocs.io.

Quickstart
----------

Install django-ordered-field::

pip install git+https://github.com/kimgea/django-ordered-field.git


In your models.py add the field you want ``OrderedField`` or ``OrderedCollectionField``:

.. code-block:: python

from django_ordered_field import OrderedField

class YourModel(models.Model):
name = models.CharField(max_length=100)
order = OrderedField()

And your ready to go.

Features
--------

* ``OrderedField`` will keep correct ordering between all instances in the enire table
* ``OrderedCollectionField`` can seperate the table in different collection based on one or more columns and keep order in each collection
* ``update_auto_now`` will update all other fields containing auto_now=True with django.utils.timezone.now if it is set to True
* ``extra_field_updates`` can be used to update other fields when their order is changed
* ``self_updates_on_collection_change`` can be used to update self (current instance) when it changes collection. Setting ``self_updates_on_collection_change_like_regular`` to True will make it use the values from the extra_field_updates

Limitations
--------

* Must user model.save(). queryset methods does not work
* Order field cant be unique or in an uniqu_togheter constraint
* 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. As a partial work-around use the ``update_auto_now``, ``extra_field_updates`` and the ``self_updates_on_collection_change`` functionalities.


Credits
-------

Based on django-positions (it did not work for django 2 at the time):

* django-positions_

.. _django-positions: https://github.com/jpwatts/django-positions

Tools used in rendering this package:

* Cookiecutter_
* `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage




History
-------

0.1.0 (2018-04-28)
++++++++++++++++++

* First release on PyPI.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-ordered-field-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

django_ordered_field-1.0.0-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-ordered-field-1.0.0.tar.gz.

File metadata

  • Download URL: django-ordered-field-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for django-ordered-field-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91c25fca0ad31ee678ee139708b1038e8d30b432c967f709a2d146d24484e64c
MD5 12ab87ed8dfe94316e0e39fd50c61d55
BLAKE2b-256 0e170c82444e9995a85b94082d096d700025c18c670bc882e1250bc4197d8abd

See more details on using hashes here.

File details

Details for the file django_ordered_field-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_ordered_field-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for django_ordered_field-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9170bb44327df70415f484b38cb11fd97bb2c022fe3a371e3141afeb666e11f4
MD5 793ef93829ae69630a9607bb3b2300ae
BLAKE2b-256 62a6bbdc4bba974f5dffb37a1c0c53ed611f109005a5d52f521d2767a36701f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page