django-gazing-select-widget
Choices of select widget changes while the value of another filed changes.
Install
pip install django-gazing-select-widget
DjangoGazingSelectWidget Init Parameters
class DjangoGazingSelectWidget(Select):
def __init__(self,
gazing_field_name,
this_field_name,
choices_related=None,
gazing_related=True,
optgroups_related=None,
empty_label="-"*10,
hide_all_if_empty=True,
attrs=None,
choices=(),
):
...
- gazing_field_name: Name of the gazing field.
- this_field_name: Name of this field.
- choices_related: List of tuple (option_value, related_value)
- It means, if the gazing_field value equals to related_value, then the option with option_value will be show.
- gazing_related: Default to true, means gazing field is at the same level with this field.
- If set to false, then the gazing field is always at the top level of the form.
- empty_label: Defualt to "-"*10. Empty value option for this field.
- hide_all_if_empty: Default to true. If true, hide all options if gazing value is empty. If false, show all options if gazing value is empty.
- attrs: Same with system's default Select widget.
- choices: Same with system's default Select widget.
- choices can be a callable object, if it's a callable object, it will be called again before get_context.
Usage
**pro/settings.py
INSTALLED_APPS = [
...
'django_gazing_select_widget',
...
]
app/admin.py
from django.contrib import admin
from django import forms
from django_gazing_select_widget.widgets import DjangoGazingSelectWidget
from .models import Category
cat1_choices = [
("", "-"*10),
(1, "1"),
(2, "2"),
]
cat2_choices = [
("group1", [
(1, "a1"),
(2, "b1"),
(3, "c1"),
(4, "d1"),
]),
("group2", [
(5, "a2"),
(6, "b2"),
(7, "c2"),
(8, "d2"),
]),
]
cat2_choices_related = {
1: ["1"],
2: ["1"],
3: ["1"],
4: ["1"],
5: ["2"],
6: ["2"],
7: ["2"],
8: ["2"],
}
class CategoryForm(forms.ModelForm):
class Meta:
model = Category
exclude = []
widgets = {
"cat1": forms.Select(choices=cat1_choices),
"cat2": DjangoGazingSelectWidget(gazing_field="cat1", choices=cat2_choices, choices_related=cat2_choices_related, hide_all_if_empty=False),
}
class CategoryAdmin(admin.ModelAdmin):
list_display = ["cat1", "cat2", "name"]
form = CategoryForm
admin.site.register(Category, CategoryAdmin)
Note:
- field cat2 is gazing at field cat1.
- if the field cat1's value is empty, show none options in field cat2.
- if the field cat1's value is 1, show group1 options in field cat2.
- if the field cat1's value is 2, show group2 options in field cat2.
Preview
Releases
v0.1.2
- Fix callable problem.
v0.1.1
- Add callable choices support.
- Add gazing_related support.
v0.1.0
- First release.
Metadata
Release files for django-gazing-select-widget 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-gazing-select-widget-0.1.2.tar.gz | 7.0 kB | Without provenance | Details for django-gazing-select-widget-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_gazing_select_widget-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for django_gazing_select_widget-0.1.2-py3-none-any.whl |
Total release size: 14.5 kB
Release files / django-gazing-select-widget-0.1.2.tar.gz
| Download URL | django-gazing-select-widget-0.1.2.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a2acf3248f49e3cf6f20283ed3e3de9ab398ad83acc9cb7c873d3ee538c9770
|
|
BLAKE2b-256 checksum How to use checksums |
bea839145bc577ab6a2fe0ced99fd30b949ccd71c3c9ac9bdf2a764003622a60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Release files / django_gazing_select_widget-0.1.2-py3-none-any.whl
| Download URL | django_gazing_select_widget-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d8ed9fa4a9744db8aaeed62f99219922d1bbe0a7e12094058c586b08d490235
|
|
BLAKE2b-256 checksum How to use checksums |
39c08424f6250b1df8890c9492551bb7e51b8d18e519ae23d579f170ef945bea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Security for django-gazing-select-widget 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.