{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "Django Sorting Field\n====================\n.. image:: https://travis-ci.org/andersinno/django-sorting-field.svg?branch=master\n :target: https://travis-ci.org/andersinno/django-sorting-field\n.. image:: https://codecov.io/gh/andersinno/django-sorting-field/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/andersinno/django-sorting-field\n\n* This package implements a Django form field + widget for drag & drog sorting of items\n* Sorting any item with a field called ``id`` is supported\n* The drag and drop feature has been implemented with `html5sortable `_.\n\nKnown limitations\n-----------------\n\n* Refreshing the items on the widget not (yet?) supported out of the box\n* No tests\n\nExample of the widget\n---------------------\n\n.. image:: readme-media/example.gif\n\nUsage\n-----\n\nThe sort order field should be implemented on the model containing the sorted objects.\nThis allows ordering of different instances of the same item set differently.\n\nLet's say you have image CarouselPlugin, Carousel, and Picture models, and you wish to be able to\nsort the same Carousel instance differently on each CarouselPlugin.\n\nYou also have a CMSPlugin object for the carousel.\n\n.. code-block:: python\n\n\tclass Carousel(models.Model):\n\t\tpass\n\n\n\tclass Picture(models.Model):\n\t\tcarousel = models.ForeignKey(Carousel, related_name=\"pictures\")\n\t\timage = SomeImageField()\n\t\tname = models.CharField()\n\n\n\tclass CarouselPlugin(CMSPlugin):\n\t\tcarousel = models.ForeignKey(Carousel, related_name=\"x\")\n\n\n\tclass CMSCarouselPlugin(CMSPluginBase):\n\t\tmodel = CarouselPlugin\n\n\t\tdef render(self, context, instance, placeholder):\n\t\t\tcontext.update({\n\t\t\t\t\"pictures\": self.instance.carousel.pictures.all(),\n\t\t\t})\n\t\t\treturn context\n\n\nAchieving the wanted behavior can be done in the following steps:\n\nAdd a (nullable) TextField to the model containing the order information\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n\tclass CarouselPlugin(CMSPlugin):\n\t\tcarousel = models.ForeignKey(Carousel, related_name=\"x\")\n\t\tcarousel_order = models.TextField(null=True)\n\n\nAdd the SortingFormField to the CMS Plugin and populate it\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n\tfrom django_sorting_field.fields import SortingFormField\n\n\tclass CarouselPluginForm(forms.ModelForm):\n\t\tcarousel_order = SortingFormField()\n\n\t\tdef __init__(self, *args, **kwargs):\n\t\t\tsuper(CarouselPluginForm, self).__init__(*args, **kwargs)\n\t\t\tif self.instance.pk:\n\t\t\t\tself.fields[\"carousel_order\"].populate(\n\t\t\t\t\titems=self.instance.carousel.pictures.all(),\n\t\t\t\t)\n\n\tclass CMSCarouselPlugin(CMSPluginBase):\n\t\tmodel = CarouselPlugin\n\t\tform = CarouselPluginForm\n\n\t\tdef render(self, context, instance, placeholder):\n\t\t\tcontext.update({\n\t\t\t\t\"pictures\": self.instance.carousel.pictures.all(),\n\t\t\t})\n\t\t\treturn context\n\nFinally, sort the items passed to the context data\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n\tfrom django_sorting_field.utils import sort_by_order\n\n\t\tclass CMSCarouselPlugin(CMSPluginBase):\n\t\tmodel = CarouselPlugin\n\t\tform = CarouselPluginForm\n\n\t\tdef render(self, context, instance, placeholder):\n\t\t\tcontext.update({\n\t\t\t\t\"pictures\": sort_by_order(\n\t\t\t\t\tself.instance.carousel.pictures.all(),\n\t\t\t\t\tself.instance.carousel_order\n\t\t\t\t),\n\t\t\t})\n\t\t\treturn context\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "sorting,field,django", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-sorting-field", "package_url": "https://pypi.org/project/django-sorting-field/", "platform": "", "project_url": "https://pypi.org/project/django-sorting-field/", "project_urls": null, "release_url": "https://pypi.org/project/django-sorting-field/1.0.2/", "requires_dist": [ "django", "six" ], "requires_python": "", "summary": "Django Sorting Field", "version": "1.0.2" }, "last_serial": 3863309, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "563433cb933e76c805c509bffb10f5ad", "sha256": "d9c41254b17560eaccd71866cad3e212df9f08cfec2dd764a115f06a28380ef3" }, "downloads": -1, "filename": "django_sorting_field-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "563433cb933e76c805c509bffb10f5ad", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10726, "upload_time": "2017-10-13T10:01:27", "url": "https://files.pythonhosted.org/packages/95/33/acd9b48593298e8f880a5993c6ac5bb7b1423e714d7997b8b34d467fddf9/django_sorting_field-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4fc1ebce05bd806aacb9613ea4d4a16f", "sha256": "c3135b69450ff8f309e9cce49fec2b32dae37e3831bf3923fa680a600f8491e2" }, "downloads": -1, "filename": "django-sorting-field-1.0.1.tar.gz", "has_sig": false, "md5_digest": "4fc1ebce05bd806aacb9613ea4d4a16f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7330, "upload_time": "2017-10-13T10:01:29", "url": "https://files.pythonhosted.org/packages/43/45/50bc1b91fe90aa51715fbe2224add370e9bc95dc8f3a29477ce042db42fb/django-sorting-field-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "62c04d3f20a5d69acd3884f815281ffd", "sha256": "baf750e2fd7267c0326877bf2ca8bcb99392ba75a63dd6f3f4b4512695698337" }, "downloads": -1, "filename": "django_sorting_field-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "62c04d3f20a5d69acd3884f815281ffd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10897, "upload_time": "2017-10-26T10:27:02", "url": "https://files.pythonhosted.org/packages/71/95/d2f693c891cad708defd8cfca7613d3e4dd099381ccdca7ce188b668f83b/django_sorting_field-1.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ce4bf5c73003b786345b6e306331696f", "sha256": "e791dd6cf1deab565888875a88f05384f42ac8dfcae92562da82582a0c7dfaf9" }, "downloads": -1, "filename": "django-sorting-field-1.0.2.tar.gz", "has_sig": false, "md5_digest": "ce4bf5c73003b786345b6e306331696f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7430, "upload_time": "2017-10-26T10:27:04", "url": "https://files.pythonhosted.org/packages/5d/b1/12d7a469b47f03869de02ca0db8e17bf15ebf68e194438c6346b7a76f0ba/django-sorting-field-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "62c04d3f20a5d69acd3884f815281ffd", "sha256": "baf750e2fd7267c0326877bf2ca8bcb99392ba75a63dd6f3f4b4512695698337" }, "downloads": -1, "filename": "django_sorting_field-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "62c04d3f20a5d69acd3884f815281ffd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10897, "upload_time": "2017-10-26T10:27:02", "url": "https://files.pythonhosted.org/packages/71/95/d2f693c891cad708defd8cfca7613d3e4dd099381ccdca7ce188b668f83b/django_sorting_field-1.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ce4bf5c73003b786345b6e306331696f", "sha256": "e791dd6cf1deab565888875a88f05384f42ac8dfcae92562da82582a0c7dfaf9" }, "downloads": -1, "filename": "django-sorting-field-1.0.2.tar.gz", "has_sig": false, "md5_digest": "ce4bf5c73003b786345b6e306331696f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7430, "upload_time": "2017-10-26T10:27:04", "url": "https://files.pythonhosted.org/packages/5d/b1/12d7a469b47f03869de02ca0db8e17bf15ebf68e194438c6346b7a76f0ba/django-sorting-field-1.0.2.tar.gz" } ] }