django-sortedm2m-1.2.2/0000775000175000017500000000000012706170274015542 5ustar travistravis00000000000000django-sortedm2m-1.2.2/django_sortedm2m.egg-info/0000775000175000017500000000000012706170274022472 5ustar travistravis00000000000000django-sortedm2m-1.2.2/django_sortedm2m.egg-info/PKG-INFO0000664000175000017500000004171312706170274023575 0ustar travistravis00000000000000Metadata-Version: 1.1 Name: django-sortedm2m Version: 1.2.2 Summary: Drop-in replacement for django's many to many field with sorted relations. Home-page: http://github.com/gregmuellegger/django-sortedm2m Author: Gregor Müllegger Author-email: gregor@muellegger.de License: BSD Description: ================ django-sortedm2m ================ |pypi-badge| |build-status| ``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. Usecases ======== 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 2.6, 2.7, 3.2 and up. PyPy is supported as well. Django 1.6 and up is required. Usage ===== Use ``SortedManyToManyField`` like ``ManyToManyField`` in your models:: 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. :: 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. 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:: 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:: from django.contrib import admin class GalleryAdmin(admin.ModelAdmin): raw_id_fields = ('photos',) Contribute ========== You can find the latest development version on github_. Get there and fork it, file bugs or send me nice wishes. .. _github: http://github.com/gregmuellegger/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 However using tox will not include the tests that run against a PostgreSQL database. The project therefore contains a ``Vagrantfile`` that uses vagrant_ to setup a virtual machine including a working PostgreSQL installation. To run the postgres tests, please `install vagrant`_ and then run:: make test-postgres This will bring up and provision the virtual machine and runs the testsuite against a PostgreSQL database. .. _vagrant: http://www.vagrantup.com/ .. _install vagrant: http://www.vagrantup.com/downloads Get in touch ------------ Feel free to drop me a message about critique or feature requests. You can get in touch with me by mail_ or twitter_. .. _mail: mailto:gregor@muellegger.de .. _twitter: http://twitter.com/gregmuellegger .. |pypi-badge| image:: https://img.shields.io/pypi/v/django-sortedm2m.svg :alt: PyPI Release :target: https://pypi.python.org/pypi/django-sortedm2m .. |build-status| image:: https://travis-ci.org/gregmuellegger/django-sortedm2m.png :alt: Build Status :target: https://travis-ci.org/gregmuellegger/django-sortedm2m Changelog ========= 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/gregmuellegger/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/gregmuellegger/django-sortedm2m/issue/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/gregmuellegger/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/gregmuellegger/django-sortedm2m/pull/59 .. _#65: https://github.com/gregmuellegger/django-sortedm2m/pull/65 .. _#67: https://github.com/gregmuellegger/django-sortedm2m/pull/67 .. _#68: https://github.com/gregmuellegger/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/gregmuellegger/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/gregmuellegger/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/gregmuellegger/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/gregmuellegger/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. Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Environment :: Web Environment Classifier: Framework :: Django Classifier: Framework :: Django :: 1.5 Classifier: Framework :: Django :: 1.6 Classifier: Framework :: Django :: 1.7 Classifier: Framework :: Django :: 1.8 Classifier: Framework :: Django :: 1.9 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 django-sortedm2m-1.2.2/django_sortedm2m.egg-info/SOURCES.txt0000664000175000017500000000130712706170274024357 0ustar travistravis00000000000000AUTHORS.rst CHANGES.rst LICENSE.txt MANIFEST.in README.rst setup.py django_sortedm2m.egg-info/PKG-INFO django_sortedm2m.egg-info/SOURCES.txt django_sortedm2m.egg-info/dependency_links.txt django_sortedm2m.egg-info/not-zip-safe django_sortedm2m.egg-info/top_level.txt sortedm2m/__init__.py sortedm2m/compat.py sortedm2m/fields.py sortedm2m/forms.py sortedm2m/models.py sortedm2m/operations.py sortedm2m/locale/cs/LC_MESSAGES/django.mo sortedm2m/locale/cs/LC_MESSAGES/django.po sortedm2m/static/sortedm2m/jquery-ui.js sortedm2m/static/sortedm2m/selector-search.gif sortedm2m/static/sortedm2m/widget.css sortedm2m/static/sortedm2m/widget.js sortedm2m/templates/sortedm2m/sorted_checkbox_select_multiple_widget.htmldjango-sortedm2m-1.2.2/django_sortedm2m.egg-info/dependency_links.txt0000664000175000017500000000000112706170274026540 0ustar travistravis00000000000000 django-sortedm2m-1.2.2/django_sortedm2m.egg-info/not-zip-safe0000664000175000017500000000000112706170251024713 0ustar travistravis00000000000000 django-sortedm2m-1.2.2/django_sortedm2m.egg-info/top_level.txt0000664000175000017500000000001212706170274025215 0ustar travistravis00000000000000sortedm2m django-sortedm2m-1.2.2/sortedm2m/0000775000175000017500000000000012706170274017456 5ustar travistravis00000000000000django-sortedm2m-1.2.2/sortedm2m/locale/0000775000175000017500000000000012706170274020715 5ustar travistravis00000000000000django-sortedm2m-1.2.2/sortedm2m/locale/cs/0000775000175000017500000000000012706170274021322 5ustar travistravis00000000000000django-sortedm2m-1.2.2/sortedm2m/locale/cs/LC_MESSAGES/0000775000175000017500000000000012706170274023107 5ustar travistravis00000000000000django-sortedm2m-1.2.2/sortedm2m/locale/cs/LC_MESSAGES/django.mo0000664000175000017500000000126012706170244024702 0ustar travistravis00000000000000<\p&q+:RChoose items and order by drag & drop.FilterType into this box to filter down the list.Project-Id-Version: PACKAGE VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2014-06-23 11:45+0200 PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE Last-Translator: FULL NAME Language-Team: LANGUAGE Language: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2; Vyberte položky označením a seřaďte je přetažením.FiltrPsaním filtrujete položky.django-sortedm2m-1.2.2/sortedm2m/locale/cs/LC_MESSAGES/django.po0000664000175000017500000000210312706170244024702 0ustar travistravis00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-06-23 11:45+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" #: templates/sortedm2m/sorted_checkbox_select_multiple_widget.html:5 msgid "Type into this box to filter down the list." msgstr "Psaním filtrujete položky." #: templates/sortedm2m/sorted_checkbox_select_multiple_widget.html:6 msgid "Filter" msgstr "Filtr" #: templates/sortedm2m/sorted_checkbox_select_multiple_widget.html:20 msgid "Choose items and order by drag & drop." msgstr "Vyberte položky označením a seřaďte je přetažením." django-sortedm2m-1.2.2/sortedm2m/static/0000775000175000017500000000000012706170274020745 5ustar travistravis00000000000000django-sortedm2m-1.2.2/sortedm2m/static/sortedm2m/0000775000175000017500000000000012706170274022661 5ustar travistravis00000000000000django-sortedm2m-1.2.2/sortedm2m/static/sortedm2m/selector-search.gif0000664000175000017500000000105012706170244026424 0ustar travistravis00000000000000GIF89a<<>>jjj666ӫXXXGGG```CCCEEE}}}ccc[[[lll___乹SSSԪNNNfffŚUUU{{{ZZZ~~~???|||iii^^^ႂdddAAA!,!4- ><  +  ,A1"%:?0&.*'@DE3B92 ;#7 C= F $ 8 (5/6) ;django-sortedm2m-1.2.2/sortedm2m/static/sortedm2m/widget.css0000664000175000017500000000161012706170244024651 0ustar travistravis00000000000000.sortedm2m-container { margin-right: 10px; width: 570px; } .sortedm2m-container p.selector-filter { width: 570px; padding: 0; margin: 0; } .sortedm2m-container p.selector-filter input { width: 532px; margin: 0 0 0 4px; } ul.sortedm2m { display: block; width: 554px; min-height: 200px; max-height: 400px; overflow-x: hidden; overflow-y: auto; margin: 0; padding: 6px 8px; list-style-type: none; text-align: left; } ul.sortedm2m li { list-style-type: none; text-align: left; width: 550px; overflow: hidden; text-overflow: ellipsis; white-space: pre; } ul.sortedm2m li, ul.sortedm2m label { cursor: move; } /* required to work properly in django admin */ body.change-form .sortedm2m-container { float: left; } .module ul.sortedm2m { margin: 0; padding: 10px 0; } .hide { display: none; } django-sortedm2m-1.2.2/sortedm2m/static/sortedm2m/widget.js0000664000175000017500000001022212706170244024474 0ustar travistravis00000000000000if (jQuery === undefined) { jQuery = django.jQuery; } (function ($) { $(function () { $('.sortedm2m-container').find('ul').addClass('hide'); function prepareUl(ul) { ul.addClass('sortedm2m'); var checkboxes = ul.find('input[type=checkbox]'); var id = checkboxes.first().attr('id').match(/^(.*)_\d+$/)[1]; var name = checkboxes.first().attr('name'); checkboxes.removeAttr('name'); ul.before(''); var recalculate_value = function () { var values = []; ul.find(':checked').each(function () { values.push($(this).val()); }); $('#' + id).val(values.join(',')); }; recalculate_value(); ul.on('change','input[type=checkbox]',recalculate_value); ul.sortable({ axis: 'y', //containment: 'parent', update: recalculate_value }); return ul; } function iterateUl() { $('ul:has(.sortedm2m)').each(function () { prepareUl( $(this) ); $(this).removeClass('hide'); }); } $(".add-row a").click(iterateUl); iterateUl(); $('.sortedm2m-container .selector-filter input').each(function () { $(this).bind('input', function() { var search = $(this).val().toLowerCase(); var $el = $(this).closest('.selector-filter'); var $container = $el.siblings('ul').each(function() { // walk over each child list el and do name comparisons $(this).children().each(function() { var curr = $(this).find('label').text().toLowerCase(); if (curr.indexOf(search) === -1) { $(this).css('display', 'none'); } else { $(this).css('display', 'inherit'); } }); }); }); }); var dismissPopupFnName = 'dismissAddAnotherPopup'; // django 1.8+ if (window.dismissAddRelatedObjectPopup) { dismissPopupFnName = 'dismissAddRelatedObjectPopup'; } if (window.showAddAnotherPopup) { var django_dismissAddAnotherPopup = window[dismissPopupFnName]; window[dismissPopupFnName] = function (win, newId, newRepr) { // newId and newRepr are expected to have previously been escaped by // django.utils.html.escape. newId = html_unescape(newId); newRepr = html_unescape(newRepr); var name = windowname_to_id(win.name); var elem = $('#' + name); var sortedm2m = elem.siblings('ul.sortedm2m'); if (sortedm2m.length == 0) { // no sortedm2m widget, fall back to django's default // behaviour return django_dismissAddAnotherPopup.apply(this, arguments); } if (elem.val().length > 0) { elem.val(elem.val() + ','); } elem.val(elem.val() + newId); var id_template = ''; var maxid = 0; sortedm2m.find('li input').each(function () { var match = this.id.match(/^(.+)_(\d+)$/); id_template = match[1]; id = parseInt(match[2]); if (id > maxid) maxid = id; }); var id = id_template + '_' + (maxid + 1); var new_li = $('
  • ').append( $('