================
django-sortedm2m
================
.. image:: https://jazzband.co/static/img/badge.svg
:target: https://jazzband.co/
:alt: Jazzband
.. image:: https://img.shields.io/pypi/v/django-sortedm2m.svg
:target: https://pypi.python.org/pypi/django-sortedm2m
:alt: PyPI Release
.. image:: https://github.com/jazzband/django-sortedm2m/actions/workflows/test.yml/badge.svg?branch=master
:target: https://github.com/jazzband/django-sortedm2m/actions?query=branch%3Amaster
:alt: Build Status
.. image:: https://codecov.io/gh/jazzband/django-sortedm2m/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jazzband/django-sortedm2m
:alt: Code coverage
``sortedm2m`` is a drop-in replacement for django's own ``ManyToManyField``.
The provided ``SortedManyToManyField`` behaves like the original one but
remembers the order of added relations.
Use Cases
=========
Imagine that you have a gallery model and a photo model. Usually you want a
relation between these models so you can add multiple photos to one gallery
but also want to be able to have the same photo on many galleries.
This is where you usually can use many to many relation. The downside is that
django's default implementation doesn't provide a way to order the photos in
the gallery. So you only have a random ordering which is not suitable in most
cases.
You can work around this limitation by using the ``SortedManyToManyField``
provided by this package as drop in replacement for django's
``ManyToManyField``.
Requirements
============
**django-sortedm2m** runs on Python 3.6+ and multiple Django versions.
See the ``.github/workflows/test.yml`` configuration for the tested Django versions.
Usage
=====
Use ``SortedManyToManyField`` like ``ManyToManyField`` in your models:
.. code-block:: python
from django.db import models
from sortedm2m.fields import SortedManyToManyField
class Photo(models.Model):
name = models.CharField(max_length=50)
image = models.ImageField(upload_to='...')
class Gallery(models.Model):
name = models.CharField(max_length=50)
photos = SortedManyToManyField(Photo)
If you use the relation in your code like the following, it will remember the
order in which you have added photos to the gallery. :
.. code-block:: python
gallery = Gallery.objects.create(name='Photos ordered by name')
for photo in Photo.objects.order_by('name'):
gallery.photos.add(photo)
``SortedManyToManyField``
-------------------------
You can use the following arguments to modify the default behavior:
``sorted``
~~~~~~~~~~
**Default:** ``True``
You can set the ``sorted`` to ``False`` which will force the
``SortedManyToManyField`` in behaving like Django's original
``ManyToManyField``. No ordering will be performed on relation nor will the
intermediate table have a database field for storing ordering information.
``sort_value_field_name``
~~~~~~~~~~~~~~~~~~~~~~~~~
**Default:** ``'sort_value'``
Specifies how the field is called in the intermediate database table by which
the relationship is ordered. You can change its name if you have a legacy
database that you need to integrate into your application.
``base_class``
~~~~~~~~~~~~~~
**Default:** ``None``
You can set the ``base_class``, which is the base class of the through model of
the sortedm2m relationship between models to an abstract base class containing
a ``__str__`` method to improve the string representations of sortedm2m
relationships.
.. note::
You also could use it to add additional fields to the through model. But
please beware: These fields will not be created or modified by an
automatically created migration. You will need to take care of migrations
yourself. In most cases when you want to add another field, consider
*not* using sortedm2m but use a ordinary Django ManyToManyField and
specify `your own through model`_.
.. _your own through model: https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ManyToManyField.through
Migrating a ``ManyToManyField`` to be a ``SortedManyToManyField``
=================================================================
If you are using Django's migration framework and want to change a
``ManyToManyField`` to be a ``SortedManyToManyField`` (or the other way
around), you will find that a migration created by Django's ``makemigrations``
will not work as expected.
In order to migrate a ``ManyToManyField`` to a ``SortedManyToManyField``, you
change the field in your models to be a ``SortedManyToManyField`` as
appropriate and create a new migration with ``manage.py makemigrations``.
Before applying it, edit the migration file and change in the ``operations``
list ``migrations.AlterField`` to ``AlterSortedManyToManyField`` (import it
from ``sortedm2m.operations``). This operation will take care of changing the
intermediate tables, add the ordering field and fill in default values.
Admin
=====
``SortedManyToManyField`` provides a custom widget which can be used to sort
the selected items. It renders a list of checkboxes that can be sorted by
drag'n'drop.
To use the widget in the admin you need to add ``sortedm2m`` to your
INSTALLED_APPS settings, like:
.. code-block:: python
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'sortedm2m',
'...',
)
Otherwise it will not find the css and js files needed to sort by drag'n'drop.
Finally, make sure *not* to have the model listed in any ``filter_horizontal``
or ``filter_vertical`` tuples inside of your ``ModelAdmin`` definitions.
If you did it right, you'll wind up with something like this:
.. image:: http://i.imgur.com/HjIW7MI.jpg
It's also possible to use the ``SortedManyToManyField`` with admin's
``raw_id_fields`` option in the ``ModelAdmin`` definition. Add the name of the
``SortedManyToManyField`` to this list to get a simple text input field. The
order in which the ids are entered into the input box is used to sort the
items of the sorted m2m relation.
Example:
.. code-block:: python
from django.contrib import admin
class GalleryAdmin(admin.ModelAdmin):
raw_id_fields = ('photos',)
Contribute
==========
This is a `Jazzband <https://jazzband.co>`_ project. By contributing you agree to abide by the
`Contributor Code of Conduct <https://jazzband.co/about/conduct>`_ and follow the
`guidelines <https://jazzband.co/about/guidelines>`_.
You can find the latest development version on Github_. Get there and fork it, file bugs or send well wishes.
.. _github: http://github.com/jazzband/django-sortedm2m
Running the tests
-----------------
I recommend to use ``tox`` to run the tests for all relevant python versions
all at once. Therefore install ``tox`` with ``pip install tox``, then type in
the root directory of the ``django-sortedm2m`` checkout::
tox
The tests are run against SQLite, then against PostgreSQL, then against mySQL -
so you need to install PostgreSQL and mySQL on your dev environment, and should
have a role/user ``sortedm2m`` set up for both PostgreSQL and mySQL.
Code Quality
------------
This project uses `isort <https://github.com/timothycrosley/isort>`_, `pycodestyle <https://github.com/PyCQA/pycodestyle>`_,
and `pylint <https://www.pylint.org>`_ to manage validate code quality. These validations can be run with the
following command::
tox -e quality
Changelog
=========
4.0.0
-----
* `#216`_: Dropped support for outdated versions of Django and Python
* `#215`_: Added support for Django 5.1
.. _#215: https://github.com/jazzband/django-sortedm2m/pull/215
.. _#216: https://github.com/jazzband/django-sortedm2m/pull/215
3.1.1
-----
* `#191`_: Fixed JS bug for popup in Django admin
.. _#191: https://github.com/jazzband/django-sortedm2m/pull/191
3.1.0
-----
* `#178`_: Bug fixes
* `#178`_: Fixed Pylint error
* `#175`_: Fixed jQuery UI error
* `#183`_: Migrated to GitHub Actions for CI
* `#184`_: Added support for Django 3.2
.. _#170: https://github.com/jazzband/django-sortedm2m/pull/170
.. _#178: https://github.com/jazzband/django-sortedm2m/pull/178
.. _#175: https://github.com/jazzband/django-sortedm2m/pull/175
.. _#183: https://github.com/jazzband/django-sortedm2m/pull/183
.. _#184: https://github.com/jazzband/django-sortedm2m/pull/184
3.0.2
-----
* `#168`_: Restored `admin/js/jquery.init.js`
.. _#168: https://github.com/jazzband/django-sortedm2m/pull/168
3.0.1
-----
* `#164`_: Added all locales to distributable
* `#162`_: Added missing files to MANIFEST.in, and removed .DS_Store files
* `#150`_: Added German and Spanish translations
* `#149`_: Removed `admin/js/jquery.init.js` from `SortedCheckboxSelectMultiple`
.. _#164: https://github.com/jazzband/django-sortedm2m/pull/164
.. _#162: https://github.com/jazzband/django-sortedm2m/pull/162
.. _#150: https://github.com/jazzband/django-sortedm2m/pull/150
.. _#149: https://github.com/jazzband/django-sortedm2m/pull/149
3.0.0
-----
* `#147`_: Dropped support for Django 2.0
* `#152`_: Dropped support for Django 1.10
* `#152`_: Add support for Python 3.8
* `#152`_: Add support for Django 3.0
.. _#147: https://github.com/jazzband/django-sortedm2m/issues/147
.. _#152: https://github.com/jazzband/django-sortedm2m/issues/152
2.0.0
-----
* `#135`_: Updated README with Jazzband details, and added CONTRIBUTING.md
* `#136`_: Dropped support for Python 2.6 and 3.3, and Django < 1.11
* `#130`_: Added support for Python 3.7 and Django 2.0 to 2.2
* `#130`_: Add support of custom through models (only for Django >= 2.2)
* `#138`_: Added coverage reporting
.. _#130: https://github.com/jazzband/django-sortedm2m/issues/130
.. _#135: https://github.com/jazzband/django-sortedm2m/pull/135
.. _#136: https://github.com/jazzband/django-sortedm2m/pull/136
.. _#138: https://github.com/jazzband/django-sortedm2m/pull/138
1.5.0
-----
* `#101`_: Add support for a custom base class for the many to many intermediate
class. See the README for documentation. Thank you Rohith Asrk for the patch.
* `#87`_: Fix ``AlterSortedManyToManyField`` operation to support custom set
``_sort_field_name``.
.. _#101: https://github.com/jazzband/django-sortedm2m/pull/101
.. _#87: https://github.com/jazzband/django-sortedm2m/issues/87
1.4.0
-----
* `#104`_: Add compatibility for Django 1.10 and 1.11!
Thank you Frankie Dintino for the patch.
* `#94`_: Add french translation files. Mainly for strings in the admin.
Thanks to ppython for the patch.
* `#93`_: Prevent users from accidentally importing and using
``ManyToManyField`` instead of ``SortedManyToManyField`` from ``sortedm2m``.
Thanks Dayne May for the patch.
.. _#104: https://github.com/jazzband/django-sortedm2m/pull/104
.. _#94: https://github.com/jazzband/django-sortedm2m/pull/94
.. _#93: https://github.com/jazzband/django-sortedm2m/pull/93
1.3.3
-----
* `#91`_ & `#92`_: Fix admin widget, when used with Django 1.10. The add a new
item opup was not closing. Thanks to Tipuch for the patch.
.. _#91: https://github.com/jazzband/django-sortedm2m/issues/91
.. _#92: https://github.com/jazzband/django-sortedm2m/pull/92
1.3.2
-----
* `#80`_ & `#83`_: Fix ``SortedMultipleChoiceField.clean`` if the validated
value is ``None``. Thanks to Alex Mannhold for the patch.
.. _#80: https://github.com/jazzband/django-sortedm2m/issues/80
.. _#83: https://github.com/jazzband/django-sortedm2m/pull/83
1.3.1
-----
* `#57`_ & `#81`_: Fix add related object popup error prevents operation when
no related objects already exist. Thanks to Vadim Sikora for the fix.
.. _#57: https://github.com/jazzband/django-sortedm2m/issue/57
.. _#81: https://github.com/jazzband/django-sortedm2m/pull/81
1.3.0
-----
* `#79`_: Use `.sortedm2m-item` selector in the widget's JavaScript code to
target the list items. This was previously `ul.sortedm2m li`. This improves
compatibility other markup that does not want to use `ul`/`li` tags. Thanks
to Michal Dabski for the patch.
**Note:** If you use custom markup with the JavaScript code, you need to make
sure that the items now have the `sortedm2m-item` class name.
* `#76`_: Add support for to_field_name to SortedMultipleChoiceField. Thanks
to Conrad Kramer for the patch.
.. _#76: https://github.com/jazzband/django-sortedm2m/pull/76
.. _#79: https://github.com/jazzband/django-sortedm2m/pull/79
1.2.2
-----
* `#75`_: Fix "add another" admin popup. It didn't refresh the list of items in Django
1.8+. Thanks to Vadim Sikora for the patch.
.. _#75: https://github.com/jazzband/django-sortedm2m/pull/75
1.2.1
-----
* *skipped*
1.2.0
-----
* Dropping Python 3.2 support. It has reached end of life in February 2016.
1.1.2
-----
* `#71`_: Don't break collectstatic for some cases. Therefore we removed the
STATIC_URL prefix from the form media definition in
``SortedCheckboxSelectMultiple``. Thanks to Kirill Ermolov for the
patch.
.. _#71: https://github.com/jazzband/django-sortedm2m/issues/71
1.1.1
-----
* `#70`_: CSS fix for Django 1.9 new admin design. Thanks to Maarten Draijer
for the patch.
.. _#70: https://github.com/jazzband/django-sortedm2m/pull/70
1.1.0
-----
* `#59`_, `#65`_, `#68`_: Django 1.9 support. Thanks to Scott Kyle and Jasper Maes for
patches.
* `#67`_: Support for disabling migrations for some models, that can be
decided by Django's DB router (with the ``allow_migrate_model`` method).
Thanks to @hstanev for the patch.
.. _#59: https://github.com/jazzband/django-sortedm2m/pull/59
.. _#65: https://github.com/jazzband/django-sortedm2m/pull/65
.. _#67: https://github.com/jazzband/django-sortedm2m/pull/67
.. _#68: https://github.com/jazzband/django-sortedm2m/pull/68
1.0.2
-----
* `#56`_: Fix bug where order is wrong after adding objects. That had to do
with using the ``count`` of the m2m objects for the next ``sort_value``
value. We now use the corret ``Max`` aggregation to make sure that newly
added objects will be in order. Thanks to Scott Kyle for the report and
patch.
.. _#56: https://github.com/jazzband/django-sortedm2m/pull/56
1.0.1
-----
* Performance fix for sorted m2m admin widget. See `#54`_ for details. Thanks
to Jonathan Liuti for fixing this.
.. _#54: https://github.com/jazzband/django-sortedm2m/pull/54
1.0.0
-----
* Hooray, we officially declare **django-sortedm2m** to be stable and
promise to be backwards compatible to new releases (we already doing good
since since the beginning in that regard).
* Django 1.8 support for ``AlterSortedManyToManyField`` operation. Thanks to
Nicolas Trésegnie for starting the implementation.
0.10.0
------
* The creation of the sortedm2m intermediate model and database table is now
fully done inside of the ``SortedManyToManyField`` class. That makes it much
easier to modify the creation of this when creating a custom subclass of this
field. See `#49`_ for an example usecase.
* Adding support for the custom field arguments like ``sorted`` and
``sort_value_field_name`` in Django 1.7 migrations. Thanks to Christian
Kohlstedde for the patch.
.. _#49: https://github.com/jazzband/django-sortedm2m/issues/49
0.9.5
-----
* Fixing ``setup.py`` when run on a system that does not use UTF-8 as default
encoding. See `#48`_ for details. Thanks to Richard Mitchell for the patch.
.. _#48: https://github.com/jazzband/django-sortedm2m/pull/48
0.9.4
-----
* Fix: ``SortedMultipleChoiceField`` did not properly report changes of the
data to ``Form.changed_data``. Thanks to @smcoll for the patch.
0.9.3
-----
* Fix: ``AlterSortedManyToManyField`` operation failed for postgres databases.
* Testing against MySQL databases.
0.9.2
-----
* Fix: ``AlterSortedManyToManyField`` operation failed for many to many fields
which already contained some data.
0.9.1
-----
* Fix: When using the sortable admin widget, deselecting an item in the list
had not effect. Thank you to madEng84 for the report and patch!
0.9.0
-----
* Adding ``AlterSortedManyToManyField`` migration operation that allows you to
migrate from ``ManyToManyField`` to ``SortedManyToManyField`` and vice
versa. Thanks to Joaquín Pérez for the patch!
* Fix: Supporting migrations in Django 1.7.4.
* Fix: The admin widget is not broken anymore for dynamically added inline
forms. Thanks to Rubén Díaz for the patch!
0.8.1
-----
* Adding support for Django 1.7 migrations. Thanks to Patryk Hes and Richard
Barran for their reports.
* Adding czech translations. Thanks to @cuchac for the pull request.
0.8.0
-----
* Adding support for Django 1.7 and dropping support for Django 1.4.
0.7.0
-----
* Adding support for ``prefetch_related()``. Thanks to Marcin Ossowski for
the idea and patch.
0.6.1
-----
* Correct escaping of *for* attribute in label for the sortedm2m widget. Thanks
to Mystic-Mirage for the report and fix.
0.6.0
-----
* Python 3 support!
* Better widget. Thanks to Mike Knoop for the initial patch.
0.5.0
-----
* Django 1.5 support. Thanks to Antti Kaihola for the patches.
* Dropping Django 1.3 support. Please use django-sortedm2m<0.5 if you need to
use Django 1.3.
* Adding support for a ``sort_value_field_name`` argument in
``SortedManyToManyField``. Thanks to Trey Hunner for the idea.
0.4.0
-----
* Django 1.4 support. Thanks to Flavio Curella for the patch.
* south support is only enabled if south is actually in your INSTALLED_APPS
setting. Thanks to tcmb for the report and Florian Ilgenfritz for the patch.
0.3.3
-----
* South support (via monkeypatching, but anyway... it's there!). Thanks to
Chris Church for the patch. South migrations won't pick up a changed
``sorted`` argument though.
0.3.2
-----
* Use already included jQuery version in global scope and don't override with
django's version. Thank you to Hendrik van der Linde for reporting this
issue.
0.3.1
-----
* Fixed packaging error.
0.3.0
-----
* Heavy internal refactorings. These were necessary to solve a problem with
``SortedManyToManyField`` and a reference to ``'self'``.
0.2.5
-----
* Forgot to exclude debug print/console.log statements from code. Sorry.
0.2.4
-----
* Fixing problems with ``SortedCheckboxSelectMultiple`` widget, especially in
admin where a "create and add another item" popup is available.
0.2.3
-----
* Fixing issue with primary keys instead of model instances for ``.add()`` and
``.remove()`` methods in ``SortedRelatedManager``.
0.2.2
-----
* Fixing validation error for ``SortedCheckboxSelectMultiple``. It caused
errors if only one value was passed.
0.2.1
-----
* Removed unnecessary reference of jquery ui css file in
``SortedCheckboxSelectMultiple``. Thanks to Klaas van Schelven and Yuwei Yu
for the hint.
0.2.0
-----
* Added a widget for use in admin.
Raw data
{
"_id": null,
"home_page": "https://github.com/jazzband/django-sortedm2m",
"name": "django-sortedm2m",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Gregor M\u00fcllegger",
"author_email": "gregor@muellegger.de",
"download_url": null,
"platform": null,
"description": "================\ndjango-sortedm2m\n================\n\n.. image:: https://jazzband.co/static/img/badge.svg\n :target: https://jazzband.co/\n :alt: Jazzband\n\n.. image:: https://img.shields.io/pypi/v/django-sortedm2m.svg\n :target: https://pypi.python.org/pypi/django-sortedm2m\n :alt: PyPI Release\n\n.. image:: https://github.com/jazzband/django-sortedm2m/actions/workflows/test.yml/badge.svg?branch=master\n :target: https://github.com/jazzband/django-sortedm2m/actions?query=branch%3Amaster\n :alt: Build Status\n\n.. image:: https://codecov.io/gh/jazzband/django-sortedm2m/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/jazzband/django-sortedm2m\n :alt: Code coverage\n\n``sortedm2m`` is a drop-in replacement for django's own ``ManyToManyField``.\nThe provided ``SortedManyToManyField`` behaves like the original one but\nremembers the order of added relations.\n\nUse Cases\n=========\n\nImagine that you have a gallery model and a photo model. Usually you want a\nrelation between these models so you can add multiple photos to one gallery\nbut also want to be able to have the same photo on many galleries.\n\nThis is where you usually can use many to many relation. The downside is that\ndjango's default implementation doesn't provide a way to order the photos in\nthe gallery. So you only have a random ordering which is not suitable in most\ncases.\n\nYou can work around this limitation by using the ``SortedManyToManyField``\nprovided by this package as drop in replacement for django's\n``ManyToManyField``.\n\nRequirements\n============\n\n**django-sortedm2m** runs on Python 3.6+ and multiple Django versions.\nSee the ``.github/workflows/test.yml`` configuration for the tested Django versions.\n\nUsage\n=====\n\nUse ``SortedManyToManyField`` like ``ManyToManyField`` in your models:\n\n.. code-block:: python\n\n from django.db import models\n from sortedm2m.fields import SortedManyToManyField\n\n class Photo(models.Model):\n name = models.CharField(max_length=50)\n image = models.ImageField(upload_to='...')\n\n class Gallery(models.Model):\n name = models.CharField(max_length=50)\n photos = SortedManyToManyField(Photo)\n\nIf you use the relation in your code like the following, it will remember the\norder in which you have added photos to the gallery. :\n\n.. code-block:: python\n\n gallery = Gallery.objects.create(name='Photos ordered by name')\n for photo in Photo.objects.order_by('name'):\n gallery.photos.add(photo)\n\n``SortedManyToManyField``\n-------------------------\n\nYou can use the following arguments to modify the default behavior:\n\n``sorted``\n~~~~~~~~~~\n\n**Default:** ``True``\n\nYou can set the ``sorted`` to ``False`` which will force the\n``SortedManyToManyField`` in behaving like Django's original\n``ManyToManyField``. No ordering will be performed on relation nor will the\nintermediate table have a database field for storing ordering information.\n\n``sort_value_field_name``\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\n**Default:** ``'sort_value'``\n\nSpecifies how the field is called in the intermediate database table by which\nthe relationship is ordered. You can change its name if you have a legacy\ndatabase that you need to integrate into your application.\n\n``base_class``\n~~~~~~~~~~~~~~\n\n**Default:** ``None``\n\nYou can set the ``base_class``, which is the base class of the through model of\nthe sortedm2m relationship between models to an abstract base class containing\na ``__str__`` method to improve the string representations of sortedm2m\nrelationships.\n\n.. note::\n\n You also could use it to add additional fields to the through model. But\n please beware: These fields will not be created or modified by an\n automatically created migration. You will need to take care of migrations\n yourself. In most cases when you want to add another field, consider\n *not* using sortedm2m but use a ordinary Django ManyToManyField and\n specify `your own through model`_.\n\n.. _your own through model: https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ManyToManyField.through\n\nMigrating a ``ManyToManyField`` to be a ``SortedManyToManyField``\n=================================================================\n\nIf you are using Django's migration framework and want to change a\n``ManyToManyField`` to be a ``SortedManyToManyField`` (or the other way\naround), you will find that a migration created by Django's ``makemigrations``\nwill not work as expected.\n\nIn order to migrate a ``ManyToManyField`` to a ``SortedManyToManyField``, you\nchange the field in your models to be a ``SortedManyToManyField`` as\nappropriate and create a new migration with ``manage.py makemigrations``.\nBefore applying it, edit the migration file and change in the ``operations``\nlist ``migrations.AlterField`` to ``AlterSortedManyToManyField`` (import it\nfrom ``sortedm2m.operations``). This operation will take care of changing the\nintermediate tables, add the ordering field and fill in default values.\n\nAdmin\n=====\n\n``SortedManyToManyField`` provides a custom widget which can be used to sort\nthe selected items. It renders a list of checkboxes that can be sorted by\ndrag'n'drop.\n\nTo use the widget in the admin you need to add ``sortedm2m`` to your\nINSTALLED_APPS settings, like:\n\n.. code-block:: python\n\n INSTALLED_APPS = (\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.sites',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n 'django.contrib.admin',\n\n 'sortedm2m',\n\n '...',\n )\n\nOtherwise it will not find the css and js files needed to sort by drag'n'drop.\n\nFinally, make sure *not* to have the model listed in any ``filter_horizontal``\nor ``filter_vertical`` tuples inside of your ``ModelAdmin`` definitions.\n\nIf you did it right, you'll wind up with something like this:\n\n.. image:: http://i.imgur.com/HjIW7MI.jpg\n\nIt's also possible to use the ``SortedManyToManyField`` with admin's\n``raw_id_fields`` option in the ``ModelAdmin`` definition. Add the name of the\n``SortedManyToManyField`` to this list to get a simple text input field. The\norder in which the ids are entered into the input box is used to sort the\nitems of the sorted m2m relation.\n\nExample:\n\n.. code-block:: python\n\n from django.contrib import admin\n\n class GalleryAdmin(admin.ModelAdmin):\n raw_id_fields = ('photos',)\n\nContribute\n==========\nThis is a `Jazzband <https://jazzband.co>`_ project. By contributing you agree to abide by the\n`Contributor Code of Conduct <https://jazzband.co/about/conduct>`_ and follow the\n`guidelines <https://jazzband.co/about/guidelines>`_.\n\nYou can find the latest development version on Github_. Get there and fork it, file bugs or send well wishes.\n\n.. _github: http://github.com/jazzband/django-sortedm2m\n\nRunning the tests\n-----------------\n\nI recommend to use ``tox`` to run the tests for all relevant python versions\nall at once. Therefore install ``tox`` with ``pip install tox``, then type in\nthe root directory of the ``django-sortedm2m`` checkout::\n\n tox\n\nThe tests are run against SQLite, then against PostgreSQL, then against mySQL -\nso you need to install PostgreSQL and mySQL on your dev environment, and should\nhave a role/user ``sortedm2m`` set up for both PostgreSQL and mySQL.\n\nCode Quality\n------------\nThis project uses `isort <https://github.com/timothycrosley/isort>`_, `pycodestyle <https://github.com/PyCQA/pycodestyle>`_,\nand `pylint <https://www.pylint.org>`_ to manage validate code quality. These validations can be run with the\nfollowing command::\n\n tox -e quality\n\n\nChangelog\n=========\n\n4.0.0\n-----\n* `#216`_: Dropped support for outdated versions of Django and Python\n* `#215`_: Added support for Django 5.1\n\n.. _#215: https://github.com/jazzband/django-sortedm2m/pull/215\n.. _#216: https://github.com/jazzband/django-sortedm2m/pull/215\n\n3.1.1\n-----\n* `#191`_: Fixed JS bug for popup in Django admin\n\n.. _#191: https://github.com/jazzband/django-sortedm2m/pull/191\n\n3.1.0\n-----\n* `#178`_: Bug fixes\n* `#178`_: Fixed Pylint error\n* `#175`_: Fixed jQuery UI error\n* `#183`_: Migrated to GitHub Actions for CI\n* `#184`_: Added support for Django 3.2\n\n.. _#170: https://github.com/jazzband/django-sortedm2m/pull/170\n.. _#178: https://github.com/jazzband/django-sortedm2m/pull/178\n.. _#175: https://github.com/jazzband/django-sortedm2m/pull/175\n.. _#183: https://github.com/jazzband/django-sortedm2m/pull/183\n.. _#184: https://github.com/jazzband/django-sortedm2m/pull/184\n\n3.0.2\n-----\n* `#168`_: Restored `admin/js/jquery.init.js`\n\n.. _#168: https://github.com/jazzband/django-sortedm2m/pull/168\n\n3.0.1\n-----\n* `#164`_: Added all locales to distributable\n* `#162`_: Added missing files to MANIFEST.in, and removed .DS_Store files\n* `#150`_: Added German and Spanish translations\n* `#149`_: Removed `admin/js/jquery.init.js` from `SortedCheckboxSelectMultiple`\n\n.. _#164: https://github.com/jazzband/django-sortedm2m/pull/164\n.. _#162: https://github.com/jazzband/django-sortedm2m/pull/162\n.. _#150: https://github.com/jazzband/django-sortedm2m/pull/150\n.. _#149: https://github.com/jazzband/django-sortedm2m/pull/149\n\n3.0.0\n-----\n* `#147`_: Dropped support for Django 2.0\n* `#152`_: Dropped support for Django 1.10\n* `#152`_: Add support for Python 3.8\n* `#152`_: Add support for Django 3.0\n\n.. _#147: https://github.com/jazzband/django-sortedm2m/issues/147\n.. _#152: https://github.com/jazzband/django-sortedm2m/issues/152\n\n2.0.0\n-----\n* `#135`_: Updated README with Jazzband details, and added CONTRIBUTING.md\n* `#136`_: Dropped support for Python 2.6 and 3.3, and Django < 1.11\n* `#130`_: Added support for Python 3.7 and Django 2.0 to 2.2\n* `#130`_: Add support of custom through models (only for Django >= 2.2)\n* `#138`_: Added coverage reporting\n\n.. _#130: https://github.com/jazzband/django-sortedm2m/issues/130\n.. _#135: https://github.com/jazzband/django-sortedm2m/pull/135\n.. _#136: https://github.com/jazzband/django-sortedm2m/pull/136\n.. _#138: https://github.com/jazzband/django-sortedm2m/pull/138\n\n1.5.0\n-----\n\n* `#101`_: Add support for a custom base class for the many to many intermediate\n class. See the README for documentation. Thank you Rohith Asrk for the patch.\n* `#87`_: Fix ``AlterSortedManyToManyField`` operation to support custom set\n ``_sort_field_name``.\n\n.. _#101: https://github.com/jazzband/django-sortedm2m/pull/101\n.. _#87: https://github.com/jazzband/django-sortedm2m/issues/87\n\n1.4.0\n-----\n\n* `#104`_: Add compatibility for Django 1.10 and 1.11!\n Thank you Frankie Dintino for the patch.\n* `#94`_: Add french translation files. Mainly for strings in the admin.\n Thanks to ppython for the patch.\n* `#93`_: Prevent users from accidentally importing and using\n ``ManyToManyField`` instead of ``SortedManyToManyField`` from ``sortedm2m``.\n Thanks Dayne May for the patch.\n\n.. _#104: https://github.com/jazzband/django-sortedm2m/pull/104\n.. _#94: https://github.com/jazzband/django-sortedm2m/pull/94\n.. _#93: https://github.com/jazzband/django-sortedm2m/pull/93\n\n1.3.3\n-----\n\n* `#91`_ & `#92`_: Fix admin widget, when used with Django 1.10. The add a new\n item opup was not closing. Thanks to Tipuch for the patch.\n\n.. _#91: https://github.com/jazzband/django-sortedm2m/issues/91\n.. _#92: https://github.com/jazzband/django-sortedm2m/pull/92\n\n1.3.2\n-----\n\n* `#80`_ & `#83`_: Fix ``SortedMultipleChoiceField.clean`` if the validated\n value is ``None``. Thanks to Alex Mannhold for the patch.\n\n.. _#80: https://github.com/jazzband/django-sortedm2m/issues/80\n.. _#83: https://github.com/jazzband/django-sortedm2m/pull/83\n\n1.3.1\n-----\n\n* `#57`_ & `#81`_: Fix add related object popup error prevents operation when\n no related objects already exist. Thanks to Vadim Sikora for the fix.\n\n.. _#57: https://github.com/jazzband/django-sortedm2m/issue/57\n.. _#81: https://github.com/jazzband/django-sortedm2m/pull/81\n\n1.3.0\n-----\n\n* `#79`_: Use `.sortedm2m-item` selector in the widget's JavaScript code to\n target the list items. This was previously `ul.sortedm2m li`. This improves\n compatibility other markup that does not want to use `ul`/`li` tags. Thanks\n to Michal Dabski for the patch.\n\n **Note:** If you use custom markup with the JavaScript code, you need to make\n sure that the items now have the `sortedm2m-item` class name.\n\n* `#76`_: Add support for to_field_name to SortedMultipleChoiceField. Thanks\n to Conrad Kramer for the patch.\n\n.. _#76: https://github.com/jazzband/django-sortedm2m/pull/76\n.. _#79: https://github.com/jazzband/django-sortedm2m/pull/79\n\n1.2.2\n-----\n\n* `#75`_: Fix \"add another\" admin popup. It didn't refresh the list of items in Django\n 1.8+. Thanks to Vadim Sikora for the patch.\n\n.. _#75: https://github.com/jazzband/django-sortedm2m/pull/75\n\n1.2.1\n-----\n\n* *skipped*\n\n1.2.0\n-----\n\n* Dropping Python 3.2 support. It has reached end of life in February 2016.\n\n1.1.2\n-----\n\n* `#71`_: Don't break collectstatic for some cases. Therefore we removed the\n STATIC_URL prefix from the form media definition in\n ``SortedCheckboxSelectMultiple``. Thanks to Kirill Ermolov for the\n patch.\n\n.. _#71: https://github.com/jazzband/django-sortedm2m/issues/71\n\n1.1.1\n-----\n\n* `#70`_: CSS fix for Django 1.9 new admin design. Thanks to Maarten Draijer\n for the patch.\n\n.. _#70: https://github.com/jazzband/django-sortedm2m/pull/70\n\n1.1.0\n-----\n\n* `#59`_, `#65`_, `#68`_: Django 1.9 support. Thanks to Scott Kyle and Jasper Maes for\n patches.\n* `#67`_: Support for disabling migrations for some models, that can be\n decided by Django's DB router (with the ``allow_migrate_model`` method).\n Thanks to @hstanev for the patch.\n\n.. _#59: https://github.com/jazzband/django-sortedm2m/pull/59\n.. _#65: https://github.com/jazzband/django-sortedm2m/pull/65\n.. _#67: https://github.com/jazzband/django-sortedm2m/pull/67\n.. _#68: https://github.com/jazzband/django-sortedm2m/pull/68\n\n1.0.2\n-----\n\n* `#56`_: Fix bug where order is wrong after adding objects. That had to do\n with using the ``count`` of the m2m objects for the next ``sort_value``\n value. We now use the corret ``Max`` aggregation to make sure that newly\n added objects will be in order. Thanks to Scott Kyle for the report and\n patch.\n\n.. _#56: https://github.com/jazzband/django-sortedm2m/pull/56\n\n1.0.1\n-----\n\n* Performance fix for sorted m2m admin widget. See `#54`_ for details. Thanks\n to Jonathan Liuti for fixing this.\n\n.. _#54: https://github.com/jazzband/django-sortedm2m/pull/54\n\n1.0.0\n-----\n\n* Hooray, we officially declare **django-sortedm2m** to be stable and\n promise to be backwards compatible to new releases (we already doing good\n since since the beginning in that regard).\n* Django 1.8 support for ``AlterSortedManyToManyField`` operation. Thanks to\n Nicolas Tr\u00e9segnie for starting the implementation.\n\n0.10.0\n------\n\n* The creation of the sortedm2m intermediate model and database table is now\n fully done inside of the ``SortedManyToManyField`` class. That makes it much\n easier to modify the creation of this when creating a custom subclass of this\n field. See `#49`_ for an example usecase.\n* Adding support for the custom field arguments like ``sorted`` and\n ``sort_value_field_name`` in Django 1.7 migrations. Thanks to Christian\n Kohlstedde for the patch.\n\n.. _#49: https://github.com/jazzband/django-sortedm2m/issues/49\n\n0.9.5\n-----\n\n* Fixing ``setup.py`` when run on a system that does not use UTF-8 as default\n encoding. See `#48`_ for details. Thanks to Richard Mitchell for the patch.\n\n.. _#48: https://github.com/jazzband/django-sortedm2m/pull/48\n\n0.9.4\n-----\n\n* Fix: ``SortedMultipleChoiceField`` did not properly report changes of the\n data to ``Form.changed_data``. Thanks to @smcoll for the patch.\n\n0.9.3\n-----\n\n* Fix: ``AlterSortedManyToManyField`` operation failed for postgres databases.\n* Testing against MySQL databases.\n\n0.9.2\n-----\n\n* Fix: ``AlterSortedManyToManyField`` operation failed for many to many fields\n which already contained some data.\n\n0.9.1\n-----\n\n* Fix: When using the sortable admin widget, deselecting an item in the list\n had not effect. Thank you to madEng84 for the report and patch!\n\n0.9.0\n-----\n\n* Adding ``AlterSortedManyToManyField`` migration operation that allows you to\n migrate from ``ManyToManyField`` to ``SortedManyToManyField`` and vice\n versa. Thanks to Joaqu\u00edn P\u00e9rez for the patch!\n* Fix: Supporting migrations in Django 1.7.4.\n* Fix: The admin widget is not broken anymore for dynamically added inline\n forms. Thanks to Rub\u00e9n D\u00edaz for the patch!\n\n0.8.1\n-----\n\n* Adding support for Django 1.7 migrations. Thanks to Patryk Hes and Richard\n Barran for their reports.\n* Adding czech translations. Thanks to @cuchac for the pull request.\n\n0.8.0\n-----\n\n* Adding support for Django 1.7 and dropping support for Django 1.4.\n\n0.7.0\n-----\n\n* Adding support for ``prefetch_related()``. Thanks to Marcin Ossowski for\n the idea and patch.\n\n0.6.1\n-----\n\n* Correct escaping of *for* attribute in label for the sortedm2m widget. Thanks\n to Mystic-Mirage for the report and fix.\n\n0.6.0\n-----\n\n* Python 3 support!\n* Better widget. Thanks to Mike Knoop for the initial patch.\n\n0.5.0\n-----\n\n* Django 1.5 support. Thanks to Antti Kaihola for the patches.\n* Dropping Django 1.3 support. Please use django-sortedm2m<0.5 if you need to\n use Django 1.3.\n* Adding support for a ``sort_value_field_name`` argument in\n ``SortedManyToManyField``. Thanks to Trey Hunner for the idea.\n\n0.4.0\n-----\n\n* Django 1.4 support. Thanks to Flavio Curella for the patch.\n* south support is only enabled if south is actually in your INSTALLED_APPS\n setting. Thanks to tcmb for the report and Florian Ilgenfritz for the patch.\n\n0.3.3\n-----\n\n* South support (via monkeypatching, but anyway... it's there!). Thanks to\n Chris Church for the patch. South migrations won't pick up a changed\n ``sorted`` argument though.\n\n0.3.2\n-----\n\n* Use already included jQuery version in global scope and don't override with\n django's version. Thank you to Hendrik van der Linde for reporting this\n issue.\n\n0.3.1\n-----\n\n* Fixed packaging error.\n\n0.3.0\n-----\n\n* Heavy internal refactorings. These were necessary to solve a problem with\n ``SortedManyToManyField`` and a reference to ``'self'``.\n\n0.2.5\n-----\n\n* Forgot to exclude debug print/console.log statements from code. Sorry.\n\n0.2.4\n-----\n\n* Fixing problems with ``SortedCheckboxSelectMultiple`` widget, especially in\n admin where a \"create and add another item\" popup is available.\n\n0.2.3\n-----\n\n* Fixing issue with primary keys instead of model instances for ``.add()`` and\n ``.remove()`` methods in ``SortedRelatedManager``.\n\n0.2.2\n-----\n\n* Fixing validation error for ``SortedCheckboxSelectMultiple``. It caused\n errors if only one value was passed.\n\n0.2.1\n-----\n\n* Removed unnecessary reference of jquery ui css file in\n ``SortedCheckboxSelectMultiple``. Thanks to Klaas van Schelven and Yuwei Yu\n for the hint.\n\n0.2.0\n-----\n\n* Added a widget for use in admin.\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Drop-in replacement for Django's many to many field with sorted relations.",
"version": "4.0.0",
"project_urls": {
"Homepage": "https://github.com/jazzband/django-sortedm2m"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f59368d68a415b2818dcf95044a14caa435d0140960be3b23ea8b264c8afda7",
"md5": "551d1f5a49c035469fcdbb690376c860",
"sha256": "7e76f3f3ea3184b4ca1d4043ec75316c606d00f5534fc71e69981d8b2198ff33"
},
"downloads": -1,
"filename": "django_sortedm2m-4.0.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "551d1f5a49c035469fcdbb690376c860",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 37782,
"upload_time": "2024-08-11T23:33:44",
"upload_time_iso_8601": "2024-08-11T23:33:44.926276Z",
"url": "https://files.pythonhosted.org/packages/4f/59/368d68a415b2818dcf95044a14caa435d0140960be3b23ea8b264c8afda7/django_sortedm2m-4.0.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-11 23:33:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jazzband",
"github_project": "django-sortedm2m",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "coverage",
"specs": [
[
"==",
"7.6.1"
]
]
},
{
"name": "isort",
"specs": [
[
"==",
"5.13.2"
]
]
},
{
"name": "pycodestyle",
"specs": [
[
"==",
"2.12.1"
]
]
},
{
"name": "pylint-django",
"specs": [
[
"==",
"2.5.5"
]
]
},
{
"name": "setuptools",
"specs": []
}
],
"tox": true,
"lcname": "django-sortedm2m"
}