django-cascading-dropdown-widget


Namedjango-cascading-dropdown-widget JSON
Version 0.2.7 PyPI version JSON
download
home_page
SummaryProvide a cascading-dropdown widget for django.
upload_time2023-09-14 12:36:48
maintainerLi Su
docs_urlNone
authorLi Su
requires_python
licenseMIT
keywords django admin extentions django cascading dropdown widget
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-cascading-dropdown-widget

Provide a cascading-dropdown widget for django.

## Install

```shell
pip install django-cascading-dropdown-widget
```

## Usage

**pro/settings.py**

**Note:**

- The application used template of django_cascading_dropdown_widget, so MUST include django_cascading_dropdown_widget in INSTALLED_APPS.

```python
INSTALLED_APPS = [
    ...
    'django_cascading_dropdown_widget',
    ...
]
```

**app/admin.py**

**Note:**

- Create a new ModelForm, and setting field widget to DjangoCascadingDropdownWidget.
- Create a choices generator instance.

```python
from django.contrib import admin
from django_cascading_dropdown_widget.widgets import DjangoCascadingDropdownWidget
from django_cascading_dropdown_widget.widgets import CascadingModelchoices
from django import forms
from .models import Category
from .models import Book
from .models import Character

class CharacterForm(forms.ModelForm):
    class Meta:
        model = Category
        exclude = []
        widgets = {
            "book": DjangoCascadingDropdownWidget(choices=CascadingModelchoices({
                "model": Category,
                "related_name": "books",
            },{
                "model": Book,
                "fk_name": "category",
            })),
        }

class CharacterAdmin(admin.ModelAdmin):
    form = CharacterForm
    list_display = ["name", "book"]
```

## Choices generator

### CascadingModelchoices

```python
class CascadingModelchoices(object):

    def __init__(self, *cascadings):
        ...
```
The parameters for CascadingModelchoices generator are the CASCADING-MODEL-SETTINGS(name it cascadings for short). A MODEL-SETTING(name it cascading for short)'s config items are:

- model, required. The Model class.
- related_name, required but except for the last model-setting. Use the related_name to get the queryset of the next level items.
- fk_name, required but except for the first model-setting. Which field name to get parent model.
- empty, optional. Use *empty* string instread of '----- xxx ----' in select for empty value.
- str, optional. Get item title from *str* method or property instread of get title by *str(item)*.

### SimpleChoices
### SimpleChoices2 (alias)

```python
class SimpleChoices(object):

    def __init__(self, *cascadings, empty1="-"*10, empty2="-"*10):
        ...
```

- A cascading is a tuple of (Title1, List).
- The Title1 is the first level option.
- The List is the second level selector. The List item is a tuple of (Value2, Title2).
- The Value2 is the second level option's value.
- The Title2 is the second level option's title.

### MPTTModel Choices

- Use CascadingModelchoices for the generator.
- Create *indented_title* function for the MPTTModel. You use whatever name for the *indented_title*.

    ```
    class MyModel(MPTTModel):
        def indented_title(self):
            return ("-"*4) * self.get_level() + self.name
    ```

- Setting ```"str": "indented_title"``` in cascading.
- The application django-cascading-dropdown-widget is NOT required django-mptt, so install django-mptt by youself. We have did try...except... with django-mptt's missing.

## Releases

### v0.2.7 2023/09/14

- Doc update.

### v0.2.6 2021/04/08

- Fix problems that sometimes the init change event is not triggered.

### v0.2.5 2020/12/01

- Remove arrive.js deps.
- Use django's jquery.
- Fix change event first trigger problem. We should ignore the first trigger.

### v0.2.2 2020/03/27

- Use `$(document).on("change", ".django-cascading-dropdown-widget-select", function(){...})` instead of `arrive` monitor. So now we do NOT depends on django-static-arrive.

### v0.2.1 2020/03/25

- Use django-static-arrive js file.
- Fire change event on the hidden input.

### v0.2.0 2020/03/23

- Add SimpleChoices generator.
- Add `white-space: nowrap;` for django-cascading-dropdown-widget.

### v0.1.0 2020/03/16

- Fisrt release.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "django-cascading-dropdown-widget",
    "maintainer": "Li Su",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "lisu@zencore.cn",
    "keywords": "django admin extentions,django cascading dropdown widget",
    "author": "Li Su",
    "author_email": "lisu@zencore.cn",
    "download_url": "https://files.pythonhosted.org/packages/29/16/23a4d04012ca0be7247b4552d39a9a423972bc0c97414f1a8c8e47f38347/django-cascading-dropdown-widget-0.2.7.tar.gz",
    "platform": null,
    "description": "# django-cascading-dropdown-widget\n\nProvide a cascading-dropdown widget for django.\n\n## Install\n\n```shell\npip install django-cascading-dropdown-widget\n```\n\n## Usage\n\n**pro/settings.py**\n\n**Note:**\n\n- The application used template of django_cascading_dropdown_widget, so MUST include django_cascading_dropdown_widget in INSTALLED_APPS.\n\n```python\nINSTALLED_APPS = [\n    ...\n    'django_cascading_dropdown_widget',\n    ...\n]\n```\n\n**app/admin.py**\n\n**Note:**\n\n- Create a new ModelForm, and setting field widget to DjangoCascadingDropdownWidget.\n- Create a choices generator instance.\n\n```python\nfrom django.contrib import admin\nfrom django_cascading_dropdown_widget.widgets import DjangoCascadingDropdownWidget\nfrom django_cascading_dropdown_widget.widgets import CascadingModelchoices\nfrom django import forms\nfrom .models import Category\nfrom .models import Book\nfrom .models import Character\n\nclass CharacterForm(forms.ModelForm):\n    class Meta:\n        model = Category\n        exclude = []\n        widgets = {\n            \"book\": DjangoCascadingDropdownWidget(choices=CascadingModelchoices({\n                \"model\": Category,\n                \"related_name\": \"books\",\n            },{\n                \"model\": Book,\n                \"fk_name\": \"category\",\n            })),\n        }\n\nclass CharacterAdmin(admin.ModelAdmin):\n    form = CharacterForm\n    list_display = [\"name\", \"book\"]\n```\n\n## Choices generator\n\n### CascadingModelchoices\n\n```python\nclass CascadingModelchoices(object):\n\n    def __init__(self, *cascadings):\n        ...\n```\nThe parameters for CascadingModelchoices generator are the CASCADING-MODEL-SETTINGS(name it cascadings for short). A MODEL-SETTING(name it cascading for short)'s config items are:\n\n- model, required. The Model class.\n- related_name, required but except for the last model-setting. Use the related_name to get the queryset of the next level items.\n- fk_name, required but except for the first model-setting. Which field name to get parent model.\n- empty, optional. Use *empty* string instread of '----- xxx ----' in select for empty value.\n- str, optional. Get item title from *str* method or property instread of get title by *str(item)*.\n\n### SimpleChoices\n### SimpleChoices2 (alias)\n\n```python\nclass SimpleChoices(object):\n\n    def __init__(self, *cascadings, empty1=\"-\"*10, empty2=\"-\"*10):\n        ...\n```\n\n- A cascading is a tuple of (Title1, List).\n- The Title1 is the first level option.\n- The List is the second level selector. The List item is a tuple of (Value2, Title2).\n- The Value2 is the second level option's value.\n- The Title2 is the second level option's title.\n\n### MPTTModel Choices\n\n- Use CascadingModelchoices for the generator.\n- Create *indented_title* function for the MPTTModel. You use whatever name for the *indented_title*.\n\n    ```\n    class MyModel(MPTTModel):\n        def indented_title(self):\n            return (\"-\"*4) * self.get_level() + self.name\n    ```\n\n- Setting ```\"str\": \"indented_title\"``` in cascading.\n- The application django-cascading-dropdown-widget is NOT required django-mptt, so install django-mptt by youself. We have did try...except... with django-mptt's missing.\n\n## Releases\n\n### v0.2.7 2023/09/14\n\n- Doc update.\n\n### v0.2.6 2021/04/08\n\n- Fix problems that sometimes the init change event is not triggered.\n\n### v0.2.5 2020/12/01\n\n- Remove arrive.js deps.\n- Use django's jquery.\n- Fix change event first trigger problem. We should ignore the first trigger.\n\n### v0.2.2 2020/03/27\n\n- Use `$(document).on(\"change\", \".django-cascading-dropdown-widget-select\", function(){...})` instead of `arrive` monitor. So now we do NOT depends on django-static-arrive.\n\n### v0.2.1 2020/03/25\n\n- Use django-static-arrive js file.\n- Fire change event on the hidden input.\n\n### v0.2.0 2020/03/23\n\n- Add SimpleChoices generator.\n- Add `white-space: nowrap;` for django-cascading-dropdown-widget.\n\n### v0.1.0 2020/03/16\n\n- Fisrt release.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Provide a cascading-dropdown widget for django.",
    "version": "0.2.7",
    "project_urls": null,
    "split_keywords": [
        "django admin extentions",
        "django cascading dropdown widget"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c48d5c8041e14300caccfdc2b96345acf48338992407451706752ff4205a2b4b",
                "md5": "767245ea3e085b8721f03296349e1168",
                "sha256": "f74351d0b41be12f9d2fe9ec965fa13d62855afbce3e7922ded7aa3b6e8b12bb"
            },
            "downloads": -1,
            "filename": "django_cascading_dropdown_widget-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "767245ea3e085b8721f03296349e1168",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7126,
            "upload_time": "2023-09-14T12:36:46",
            "upload_time_iso_8601": "2023-09-14T12:36:46.801167Z",
            "url": "https://files.pythonhosted.org/packages/c4/8d/5c8041e14300caccfdc2b96345acf48338992407451706752ff4205a2b4b/django_cascading_dropdown_widget-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "291623a4d04012ca0be7247b4552d39a9a423972bc0c97414f1a8c8e47f38347",
                "md5": "79a157f1c2b9f50f6ab076a71f1977ca",
                "sha256": "3915b6d0737ab58788c5bd8d4b9d9a3ae18b6aec416da46585275bd02ee517de"
            },
            "downloads": -1,
            "filename": "django-cascading-dropdown-widget-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "79a157f1c2b9f50f6ab076a71f1977ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7581,
            "upload_time": "2023-09-14T12:36:48",
            "upload_time_iso_8601": "2023-09-14T12:36:48.701830Z",
            "url": "https://files.pythonhosted.org/packages/29/16/23a4d04012ca0be7247b4552d39a9a423972bc0c97414f1a8c8e47f38347/django-cascading-dropdown-widget-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 12:36:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "django-cascading-dropdown-widget"
}
        
Elapsed time: 0.24279s