{ "info": { "author": "Patrick Lauber", "author_email": "digi@treepy.com", "bugtrack_url": null, "classifiers": [], "description": "# Django Smart Selects\n\n[![Build Status](https://travis-ci.org/digi604/django-smart-selects.svg?branch=master)](https://travis-ci.org/digi604/django-smart-selects)\n\n[![Coverage Status](https://coveralls.io/repos/github/digi604/django-smart-selects/badge.svg?branch=master)](https://coveralls.io/github/digi604/django-smart-selects?branch=master)\n\n\nThis package allows you to quickly filter or group \"chained\" models by adding a custom foreign key or many to many field to your models. This will use an AJAX query to load only the applicable chained objects.\n\n**Warning**: The AJAX endpoint enforces no permissions by default. This means that **any model with a chained field will be world readable**. If you would like more control over this permission, the [`django-autocomplete-light`](https://github.com/yourlabs/django-autocomplete-light) package is a great, high-quality package that enables the same functionality with permission checks.\n\n## Chained Selects\n\nGiven the following model:\n\n```python\nclass Continent(models.Model):\n name = models.CharField(max_length=255)\n\nclass Country(models.Model):\n continent = models.ForeignKey(Continent)\n name = models.CharField(max_length=255)\n\nclass Location(models.Model):\n continent = models.ForeignKey(Continent)\n country = models.ForeignKey(Country)\n area = models.ForeignKey(Area)\n city = models.CharField(max_length=50)\n street = models.CharField(max_length=100)\n```\n\nOnce you select a continent, if you want only the countries on that continent to be available, you can use a `ChainedForeignKey` on the `Location` model:\n\n```python\nfrom smart_selects.db_fields import ChainedForeignKey\n\nclass Location(models.Model)\n continent = models.ForeignKey(Continent)\n country = ChainedForeignKey(\n Country,\n chained_field=\"continent\",\n chained_model_field=\"continent\",\n show_all=False,\n auto_choose=True,\n sort=True)\n area = ForeignKey(Area)\n city = models.CharField(max_length=50)\n street = models.CharField(max_length=100)\n```\n\n### ChainedForeignKey options\n\n#### chained_field (required)\n\nThe `chained_field` indicates the field on the same model that should be chained to. In the `Continent`, `Country`, `Location` example, `chained_field` is the name of the field `continent` in model `Location`.\n\n```python\nclass Location(models.Model)\n continent = models.ForeignKey(Continent)\n```\n\n#### chained_model_field (required)\n\nThe `chained_model_field` indicates the field of the chained model that corresponds to the model linked to by the `chained_field`. In the `Continent`, `Country`, `Location` example, `chained_model_field` is the name of field `continent` in Model `Country`.\n\n```python\nclass Country(models.Model):\n continent = models.ForeignKey(Continent)\n```\n\n#### show_all (optional)\n\n`show_all` indicates if only the filtered results should be shown or if you also want to display the other results further down.\n\n#### auto_choose (optional)\n\n`auto_choose` indicates if auto select the choice when there is only one available choice.\n\n#### `sort` (optional)\n\n`sort` indicates if the result set should be sorted lexicographically or not. Disable if you want to use the `Model.ordering` option. Defaults to `True`.\n\n\n## Chained ManyToMany Selects\n\nThe `ChainedManyToManyField` works as you would expect:\n\n```python\nfrom smart_selects.db_fields import ChainedManyToManyField\n\nclass Publication(models.Model):\n name = models.CharField(max_length=255)\n\nclass Writer(models.Model):\n name = models.CharField(max_length=255)\n publications = models.ManyToManyField('Publication', blank=True, null=True)\n\nclass Book(models.Model):\n publication = models.ForeignKey(Publication)\n writer = ChainedManyToManyField(\n Writer,\n chained_field=\"publication\",\n chained_model_field=\"publications\")\n name = models.CharField(max_length=255)\n```\n\n\n### Using chained fields in the admin\n\nDo **not** specify the field in the `ModelAdmin` `filter_horizontal` list. Instead, simply pass `horizontal=True` to the `ChainedManyToManyField`:\n\n```python\nfrom smart_selects.db_fields import ChainedManyToManyField\n\nclass Publication(models.Model):\n name = models.CharField(max_length=255)\n\nclass Writer(models.Model):\n name = models.CharField(max_length=255)\n publications = models.ManyToManyField('Publication', blank=True, null=True)\n\nclass Book(models.Model):\n publication = models.ForeignKey(Publication)\n writer = ChainedManyToManyField(\n Writer,\n horizontal=True,\n verbose_name='writer',\n chained_field=\"publication\",\n chained_model_field=\"publications\")\n name = models.CharField(max_length=255)\n```\n\n\n### ChainedManyToManyField options\n\n#### `chained_field` (required)\n\nThe `chained_field` indicates the field on the same model that should be chained to. In the `Publication`, `Writer`, `Book` example, `chained_field` is the name of the field `publication` in model `Book`.\n\n```python\nclass Book(models.Model):\n publication = models.ForeignKey(Publication)\n```\n\n#### `chained_model_field` (required)\n\nThe `chained_model_field` indicates the field of the chained model that corresponds to the model linked to by the `chained_field`. In the `Publication`, `Writer`, `Book` example, `chained_model_field` is the name of field `publications` in `Writer` model.\n\n```python\nclass Writer(models.Model):\n publications = models.ManyToManyField('Publication', blank=True, null=True)\n```\n\n#### `auto_choose` (optional)\n\n`auto_choose` indicates if auto select the choice when there is only one available choice.\n\n#### `horizontal` (optional)\n\nThis option will mixin Django's `FilteredSelectMultiple` to work in the Django admin as you expect\n\n\n## Grouped Selects\n\nIf you have the following model:\n\n```python\nclass Country(models.Model):\n continent = models.ForeignKey(Continent)\n\nclass Location(models.Model):\n continent = models.ForeignKey(Continent)\n country = models.ForeignKey(Country)\n```\n\nAnd you want to group countries by their continent in the HTML select list, you can use a `GroupedForeignKey`:\n\n```python\nfrom smart_selects.db_fields import GroupedForeignKey\n\nclass Location(models.Model):\n continent = models.ForeignKey(Continent)\n country = GroupedForeignKey(Country, \"continent\")\n```\n\n\n## Installation\n\n1. Add `smart_selects` to your `INSTALLED_APPS`\n2. Add the `smart_selects` urls into your project's `urls.py`. This is needed for the `Chained Selects` and `Chained ManyToMany Selects`. For example:\n\n ```python\n urlpatterns = patterns('',\n url(r'^admin/', include(admin.site.urls)),\n url(r'^chaining/', include('smart_selects.urls')),\n )\n ```\n\n3. You will also need to include jQuery in every page that includes a field from `smart_selects`, or set `JQUERY_URL = True` in your project's `settings.py`.\n\n\n## Settings\n\n`JQUERY_URL`\n: jQuery 2.2.0 is loaded from Google's CDN if this is set to `True`. If you would prefer to\n use a different version put the full URL here. Set `JQUERY_URL = False`\n to disable loading jQuery altogether.\n\n`USE_DJANGO_JQUERY`\n: By default, `smart_selects` loads jQuery from Google's CDN. However, it can use jQuery from Django's\n admin area. Set `USE_DJANGO_JQUERY = True` to enable this behaviour.\n\n\n## TODO\n\n* Add permission checks to enable users to restrict who can use the chained fields.\n* Add a `ChainedCheckboxSelectMultiple` widget and adjust `chainedm2m.js` and `chainedfk.js` to build checkboxes in that case", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/digi604/django-smart-selects", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-smart-selects", "package_url": "https://pypi.org/project/django-smart-selects/", "platform": "", "project_url": "https://pypi.org/project/django-smart-selects/", "project_urls": { "Homepage": "https://github.com/digi604/django-smart-selects" }, "release_url": "https://pypi.org/project/django-smart-selects/1.5.4/", "requires_dist": null, "requires_python": "", "summary": "Django application to handle chained model fields.", "version": "1.5.4" }, "last_serial": 3618977, "releases": { "1.2.9": [ { "comment_text": "", "digests": { "md5": "bafd0828b4a724ae326f9c39007ee7db", "sha256": "f4228961933e7e5cce107c682306c1a3717c1f18b0122fc597831b2dc02f8e7c" }, "downloads": -1, "filename": "django-smart-selects-1.2.9.tar.gz", "has_sig": false, "md5_digest": "bafd0828b4a724ae326f9c39007ee7db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15942, "upload_time": "2017-02-01T23:52:24", "url": "https://files.pythonhosted.org/packages/35/6e/015fbf94c30ba5d3bb43667204bb0d04fff05d2d8a83b9f17503b0f37e93/django-smart-selects-1.2.9.tar.gz" } ], "1.3.1": [ { "comment_text": "", "digests": { "md5": "2e5674cc8d4ca45fe45d242468c20b53", "sha256": "630a1ac502b33ce5936117cac0d635bc3e18175de6e18c4440ac50d904b57d4d" }, "downloads": -1, "filename": "django-smart-selects-1.3.1.tar.gz", "has_sig": false, "md5_digest": "2e5674cc8d4ca45fe45d242468c20b53", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16444, "upload_time": "2017-02-02T00:17:20", "url": "https://files.pythonhosted.org/packages/ec/48/ab2a710f23d3ed656899b6348475f7be6cd6be5a576205fa9ddb594387b2/django-smart-selects-1.3.1.tar.gz" } ], "1.3.2": [ { "comment_text": "", "digests": { "md5": "cbca53fdd8d14cd0e04d1ad79b135dc3", "sha256": "1cb980be2501d89af61b47772e1a16689c880edf5ea759d282e341b39b973f2d" }, "downloads": -1, "filename": "django-smart-selects-1.3.2.tar.gz", "has_sig": false, "md5_digest": "cbca53fdd8d14cd0e04d1ad79b135dc3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16414, "upload_time": "2017-02-02T21:55:48", "url": "https://files.pythonhosted.org/packages/c4/59/5254c469ea563972ede1d7312ec446a0b2600b71b97bdd7b83973a60435b/django-smart-selects-1.3.2.tar.gz" } ], "1.3.3": [ { "comment_text": "", "digests": { "md5": "bf66e441fbacb901194143f0683910d4", "sha256": "ffc9e6d63715f161e65eccf4228106fab46766f2f4a7bcc23676958dbcf55648" }, "downloads": -1, "filename": "django-smart-selects-1.3.3.tar.gz", "has_sig": true, "md5_digest": "bf66e441fbacb901194143f0683910d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17660, "upload_time": "2017-03-08T12:03:19", "url": "https://files.pythonhosted.org/packages/4a/66/7a9d72c5b63a88a77cf1a6f3a4398967b810cb34a878f5104cf5a6477c6f/django-smart-selects-1.3.3.tar.gz" } ], "1.3.4": [ { "comment_text": "", "digests": { "md5": "b3a7e47a0af566322cece1110c0ab9a3", "sha256": "a48cd1bdc83963e89a82ade6bdf58a93c3304343afc61dbd795a8be73f6d741a" }, "downloads": -1, "filename": "django-smart-selects-1.3.4.tar.gz", "has_sig": true, "md5_digest": "b3a7e47a0af566322cece1110c0ab9a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18399, "upload_time": "2017-03-09T16:33:21", "url": "https://files.pythonhosted.org/packages/7e/76/e21f0318ec15500e7122862e09ed97b2a4fbcb5e2b41d512ee54084d0ed5/django-smart-selects-1.3.4.tar.gz" } ], "1.4.0": [ { "comment_text": "", "digests": { "md5": "317ca3096e144819f3be674a87566648", "sha256": "6fa19dd992c789651e5668c1e70a442a7cf47edf28fbc461b6140207f69dc015" }, "downloads": -1, "filename": "django-smart-selects-1.4.0.tar.gz", "has_sig": true, "md5_digest": "317ca3096e144819f3be674a87566648", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19154, "upload_time": "2017-04-19T16:00:11", "url": "https://files.pythonhosted.org/packages/c4/73/3a4d72f11874c558b20ac93d4b70653f039a56a307c693e5b81d3ad507f3/django-smart-selects-1.4.0.tar.gz" } ], "1.5.0": [ { "comment_text": "", "digests": { "md5": "bf470bdbd7380ad668fc62354b5ccdea", "sha256": "d2a48ce7147ab57c68072a148df1e000f2079df2ea72ab8819800cf0ac1bd927" }, "downloads": -1, "filename": "django-smart-selects-1.5.0.tar.gz", "has_sig": true, "md5_digest": "bf470bdbd7380ad668fc62354b5ccdea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19144, "upload_time": "2017-04-19T21:19:57", "url": "https://files.pythonhosted.org/packages/81/5a/e689eb699ddb1530a33821001c8478bfb62ae76fc625842798323cfc93ce/django-smart-selects-1.5.0.tar.gz" } ], "1.5.1": [ { "comment_text": "", "digests": { "md5": "5fa300c1bfc20d1995ef2d2a9e2edc7c", "sha256": "f9d430bc3351b4c1dcd555d11b53b682b9b67f52ef93fecad73f45474fbf1b14" }, "downloads": -1, "filename": "django-smart-selects-1.5.1.tar.gz", "has_sig": true, "md5_digest": "5fa300c1bfc20d1995ef2d2a9e2edc7c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19251, "upload_time": "2017-04-25T23:40:10", "url": "https://files.pythonhosted.org/packages/37/32/1df568acc3fe562989914e18b34c89b4b105175d2ce76846ae14c4d00b6d/django-smart-selects-1.5.1.tar.gz" } ], "1.5.2": [ { "comment_text": "", "digests": { "md5": "93aeaff30008b69373907dfb3634a069", "sha256": "f7ecf0bdae1a524ded733d6cbbddbc5ed3bf4c0eaa9543764bea3729e862716b" }, "downloads": -1, "filename": "django-smart-selects-1.5.2.tar.gz", "has_sig": true, "md5_digest": "93aeaff30008b69373907dfb3634a069", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19408, "upload_time": "2017-05-14T09:38:32", "url": "https://files.pythonhosted.org/packages/c3/19/9ae2ed56025dcc4b3b176175c1e7e80c5ecce45b4a49ee268c45b45f85a1/django-smart-selects-1.5.2.tar.gz" } ], "1.5.3": [ { "comment_text": "", "digests": { "md5": "a22f583fe6e76156d6818413b1a4b8c6", "sha256": "1796a1ae9afbd087b7bbc0e1a228ec718da0cbfa321211c0332cd2e6a4956b32" }, "downloads": -1, "filename": "django-smart-selects-1.5.3.tar.gz", "has_sig": true, "md5_digest": "a22f583fe6e76156d6818413b1a4b8c6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20529, "upload_time": "2017-12-23T02:08:21", "url": "https://files.pythonhosted.org/packages/ee/f9/09179947546abb64f2659b268463e318a6cc08a9e51a54f45c22b51eed34/django-smart-selects-1.5.3.tar.gz" } ], "1.5.4": [ { "comment_text": "", "digests": { "md5": "2120b0d552c18762eee6e7e3330e7b97", "sha256": "207025ebdbd66d2db94849e619e4898acba4544a334cff4a4541286afa36e300" }, "downloads": -1, "filename": "django-smart-selects-1.5.4.tar.gz", "has_sig": true, "md5_digest": "2120b0d552c18762eee6e7e3330e7b97", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20660, "upload_time": "2018-02-26T22:35:01", "url": "https://files.pythonhosted.org/packages/49/b4/e55587881b043ca5624bb71243da835fa520cbd5a808b5b9b075bac3e231/django-smart-selects-1.5.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2120b0d552c18762eee6e7e3330e7b97", "sha256": "207025ebdbd66d2db94849e619e4898acba4544a334cff4a4541286afa36e300" }, "downloads": -1, "filename": "django-smart-selects-1.5.4.tar.gz", "has_sig": true, "md5_digest": "2120b0d552c18762eee6e7e3330e7b97", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20660, "upload_time": "2018-02-26T22:35:01", "url": "https://files.pythonhosted.org/packages/49/b4/e55587881b043ca5624bb71243da835fa520cbd5a808b5b9b075bac3e231/django-smart-selects-1.5.4.tar.gz" } ] }