{ "info": { "author": "dannosaur", "author_email": "me@dannosaur.com", "bugtrack_url": null, "classifiers": [], "description": "Usage:\n\n* `pip install django-dynamic-form-fields`\n* Add `dynamic_fields` to `INSTALLED_APPS`\n* Add to your form as a widget:\n\n```\nfrom typing import Type\n\nfrom dynamic_fields.fields import DynamicChoicesWidget\n\nfrom myapp.models import MyModel, Item\n\n\ndef get_item_choices(model: Type[Item], value: int):\n choices = []\n\n item = model.objects.get(id=value)\n\n for thing in item.things:\n # do something with item\n choices.append({\n 'value': thing.id,\n 'label': thing.name,\n })\n\n return choices\n\n\nclass MyForm(forms.ModelForm):\n class Meta:\n model = MyModel\n fields = ('item', 'dependent_item')\n widgets = {\n 'dependent_item': DynamicChoicesWidget(\n depends_field='item',\n model=Item,\n callback=get_item_choices,\n no_value_disable=True,\n include_empty_choice=True,\n empty_choice_label=\"Please choose an option\",\n )\n }\n```\n\n* Ensure that form media is included with the rest of your view's media\n\nRequirements:\n\n* Django 1.11+\n* Python 3.5+ (built/tested with 3.6.2)\n* jQuery (built/tested with 1.12.4)\n\nHow does it work?\n\nA view is injected into the project's urlpatterns which is the handler\nfor the ajax callback when the dependent field changes. When the\nDynamicChoicesWidget template is rendered, it serializes the various\nprovided values into Python dotted strings to send to the template.\nIt uses HTML5 data attributes in the markup to pass these values to\nthe Javascript in order to send to the view to tell it what to do next.\n\nThe model is serialized into `app.model`, and the `callback` is\nserialized into the full dotted path to the method within your code,\ne.g; `app.form.my_form.get_choices`. When the dependent field's value\nis changed, the ajax calls the view with the relevant information\nfrom above, then this goes and imports the path, grabs the model\nclass for what was provided from django's model loader, then calls\nyour method with the class itself, and the value provided by the\ndependent field. The output of the callback method is serialized\nback into JSON, returned to the Javascript making the call, which\niterates over the options and resets the select box's options to\nthose provided.\n\nThese can be chained (theoretically) for as many fields as required.\nIt should also (though untested) work with multiple select boxes.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/dannosaur/django-dynamic-form-fields", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-dynamic-form-fields", "package_url": "https://pypi.org/project/django-dynamic-form-fields/", "platform": "", "project_url": "https://pypi.org/project/django-dynamic-form-fields/", "project_urls": { "Homepage": "https://gitlab.com/dannosaur/django-dynamic-form-fields" }, "release_url": "https://pypi.org/project/django-dynamic-form-fields/0.2.0/", "requires_dist": [ "django (<2.1,>=1.11)" ], "requires_python": ">=3.5", "summary": "Dynamically update choice fields based on dependent fields in django", "version": "0.2.0" }, "last_serial": 3978265, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "adfd7b57c6be2e65621bf08c859db23d", "sha256": "bbe5fec263147ac72dad4fa5f551461bd96a2d93a22793f4c1125fa872f5d2df" }, "downloads": -1, "filename": "django_dynamic_form_fields-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "adfd7b57c6be2e65621bf08c859db23d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 7128, "upload_time": "2018-06-18T18:06:38", "url": "https://files.pythonhosted.org/packages/e2/da/9cbb5b69b20168341ab3df7e42bad61bda42f5ea526d54ea62cbcf6320c0/django_dynamic_form_fields-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f0f0d8e0d832a4020dc2bb6251cdee20", "sha256": "4a88ca221e4a6535d93f400d7000537967c1b1fdfb331a6edebf24cad5640fa5" }, "downloads": -1, "filename": "django-dynamic-form-fields-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f0f0d8e0d832a4020dc2bb6251cdee20", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5513, "upload_time": "2018-06-18T18:06:39", "url": "https://files.pythonhosted.org/packages/67/15/9613c1538b077045ffd409fab390cb2a0639fe5ba6890e624cde4698a445/django-dynamic-form-fields-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "4079b28b95cac24e91ab219315eb6c11", "sha256": "48c6d56fc121641135092f95c052a828dc69f06752c841c4eb95f23bc9da99ea" }, "downloads": -1, "filename": "django_dynamic_form_fields-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4079b28b95cac24e91ab219315eb6c11", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 7279, "upload_time": "2018-06-19T17:07:27", "url": "https://files.pythonhosted.org/packages/2c/e3/39c9b9c88752790a90ed8837e33c3f2a23c069cc4698843e47969b196ca2/django_dynamic_form_fields-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "de4e47352980ac1ffc6cbba71cda9549", "sha256": "55af5ea3c0f1cc37f05564ad605adb24fb9882e169bcf344c9ce0ac9475c7ef8" }, "downloads": -1, "filename": "django-dynamic-form-fields-0.2.0.tar.gz", "has_sig": false, "md5_digest": "de4e47352980ac1ffc6cbba71cda9549", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5755, "upload_time": "2018-06-19T17:07:29", "url": "https://files.pythonhosted.org/packages/a8/c5/3397c682939b520314c966ba23c0b2dc6c9de04d7bb617cdf5b4f4f4560d/django-dynamic-form-fields-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4079b28b95cac24e91ab219315eb6c11", "sha256": "48c6d56fc121641135092f95c052a828dc69f06752c841c4eb95f23bc9da99ea" }, "downloads": -1, "filename": "django_dynamic_form_fields-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4079b28b95cac24e91ab219315eb6c11", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 7279, "upload_time": "2018-06-19T17:07:27", "url": "https://files.pythonhosted.org/packages/2c/e3/39c9b9c88752790a90ed8837e33c3f2a23c069cc4698843e47969b196ca2/django_dynamic_form_fields-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "de4e47352980ac1ffc6cbba71cda9549", "sha256": "55af5ea3c0f1cc37f05564ad605adb24fb9882e169bcf344c9ce0ac9475c7ef8" }, "downloads": -1, "filename": "django-dynamic-form-fields-0.2.0.tar.gz", "has_sig": false, "md5_digest": "de4e47352980ac1ffc6cbba71cda9549", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5755, "upload_time": "2018-06-19T17:07:29", "url": "https://files.pythonhosted.org/packages/a8/c5/3397c682939b520314c966ba23c0b2dc6c9de04d7bb617cdf5b4f4f4560d/django-dynamic-form-fields-0.2.0.tar.gz" } ] }