{ "info": { "author": "Tobias Lorenz", "author_email": "tobias.lorenz@bitmazk.com", "bugtrack_url": null, "classifiers": [], "description": "Django Generic Positions\n========================\n\nThis is a generic app for using a drag & drop position field, wherever you want\nto.\n\nYou often have items that should have a position field so that the user\ncan manipulate their ordering by entering intergers into that field. This app\nallows you to easily add drag and drop functionality to that model's Django\nadmin or even to your frontend.\n\nYou don't need to manipulate your models, which means that you can even make\nthird party models that don't have a position field at all position aware.\n\nPrerequisites\n-------------\n\nYou need at least the following packages in your virtualenv:\n\n* Django\n\n\nInstallation\n------------\n\nTo get the latest stable release from PyPi::\n\n $ pip install django-generic-positions\n\nTo get the latest commit from GitHub::\n\n $ pip install -e git://github.com/bitmazk/django-generic-positions.git#egg=generic_positions\n\nAdd the app to your ``INSTALLED_APPS``::\n\n INSTALLED_APPS = [\n ...\n 'generic_positions',\n ]\n\nAdd this to your main ``urls.py``::\n\n urlpatterns = patterns(\n '',\n url(r'^pos/', include('generic_positions.urls')),\n ...\n )\n\nRun the migrations to create the app's database tables::\n\n $ ./manage.py migrate generic_positions\n\nUsage\n-----\n\nIf you want to add the position feature to the model of a third party app,\ndo the following in one of your ``models.py`` files::\n\n from django.contrib.contenttypes.fields import GenericRelation\n from thirdpartyapp.models import TheModel\n\n TheModel.add_to_class(\n 'generic_position',\n generic.GenericRelation('generic_positions.ObjectPosition'),\n )\n\nIf you are extending on of your own models, simply add this to your model::\n\n from django.contrib.contenttypes.fields import GenericRelation\n\n class YourModel(models.Model):\n ...\n generic_position = GenericRelation(\n 'generic_positions.ObjectPosition'\n )\n\nIMPORTANT. If you are using multiple models, which have generic relations to\nthe positioning model, this is what you should NOT do: For some reason there\nwill be duplicates of your model appearing in the templates. Please don't use\n``ordering = ['generic_position__position']``.\n\n\nUsage in templates\n++++++++++++++++++\n\nThere are several template tags and filters you can use. Let's start with a\nsimple view, which orders the object list by position::\n\n {% load position_tags %}\n {% for obj in object_list|order_by_position %}\n
{{ obj }}
\n {% endfor %}\n\nYou want to reverse the ordering? Go for it::\n\n {% load position_tags %}\n {% for obj in object_list|order_by_position:'reverse' %}\n{{ obj }}
\n {% endfor %}\n\nLet's show the current position, too::\n\n {% load position_tags %}\n {% for obj in object_list|order_by_position:'reverse' %}\n{% position_input obj 'visible' %} » {{ obj }}
\n {% endfor %}\n\nThe ``position_input`` tag will add a hidden field with the position nr. and\nif you add ``visible`` it will also append a span element.\n\nIf you also want the drag & drop functionality, have a look at the following\nexample of a complete implementation::\n\n {% load position_tags %}\n \n\n # You might want to place these scripts in your base template\n \n \n \n \n \n\nA few things are important here:\n\n* You must put a form around your position aware objects\n* The form must POST to the url ``position_bulk_update``\n* Don't forget to add the ``csrf_token``\n* Inside the form you need a wrapper element that wraps all your position aware\n items. A ``