diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-10 09:19:34 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-10 09:19:34 +0000 |
commit | 24dc1acc2fafa83b4a5ffcc05118a46ec6ac53a9 (patch) | |
tree | 4620bd3dbe714b90759ebd74d0cb47834ad24359 | |
parent | a70e37b257a8bc86dac9440fa394c85bdeac7b24 (diff) |
automatic import of python-django-select2-admin-filters
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-django-select2-admin-filters.spec | 394 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 396 insertions, 0 deletions
@@ -0,0 +1 @@ +/django-select2-admin-filters-0.1.4.tar.gz diff --git a/python-django-select2-admin-filters.spec b/python-django-select2-admin-filters.spec new file mode 100644 index 0000000..f15a495 --- /dev/null +++ b/python-django-select2-admin-filters.spec @@ -0,0 +1,394 @@ +%global _empty_manifest_terminate_build 0 +Name: python-django-select2-admin-filters +Version: 0.1.4 +Release: 1 +Summary: A simple extension to Django app to render filters in django admin panel as autocomplete widget. +License: MIT +URL: https://pypi.org/project/django-select2-admin-filters/ +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ce/76/aaec26f3d1144b7a0ea46fd9d089da5418378f21b513f51cea726edf29fc/django-select2-admin-filters-0.1.4.tar.gz +BuildArch: noarch + +Requires: python3-django + +%description +## django_select2_admin_filters + +This extension is based on [django-select2](https://github.com/applegrew/django-select2) and works with or without Grappelli. + +## Installation + +* Install using pip + + ``` + pip install django-select2-admin-filters + ``` + +* Update INSTALLED_APPS, you need too put django_select2_admin_filters after admin and django_select2 + + ```python + INSTALLED_APPS = [ + 'django.contrib.admin', + # + 'django_select2', + 'django_select2_admin_filters', + ] + ``` + +* Update urls.py to use model filters (refer to [django-select2 documentation](https://django-select2.readthedocs.io/en/latest/get_started.html#installation)) + + ``` + path('select2/', include('django_select2.urls')), + ``` + +## Filters + +Filters are generally of two types, but each of them can be single or multiple selectable: +* ChoiceFilter + * ChoiceSelect2Filter + * MultipleChoiceSelect2Filter +* ModelFilter + * ModelSelect2Filter + * MultipleModelSelect2Filter + +## Usage + +* Use filter in your admin.py + ```python + from django.contrib import admin + from django_select2_admin_filters.admin import ( + Select2AdminFilterMixin) + from django_select2_admin_filters.filters import ( + ChoiceSelect2Filter, MultipleChoiceSelect2Filter, + ModelSelect2Filter, MultipleModelSelect2Filter) + from your_app.models import Country, Person, Profession + + + class CountryFilter(ModelSelect2Filter): + title = 'Country of residence' # filter's title + parameter_name = 'country' # parameter used in url and by default field name of Foreign Key used to filter results + autocomplete_queryset = Country.objects.all() # queryset to autocomplete + search_fields = ['name__icontains'] # fields of Country model used to filtering + + # optionally you can override queryset method + def queryset(self, request, queryset): + val = self.value() + if val: + return queryset.filter(country_of_residence=val) + return queryset + + + class ProfessionFilter(MultipleModelSelect2Filter): + title = 'Profession' + parameter_name = 'profession' + autocomplete_queryset = Profession.objects.all() + search_fields = ['name__icontains'] + + def queryset(self, request, queryset): + val = self.value_as_list() + if len(val) > 0: + return queryset.filter(professions__profession_id__in=val) + return queryset + + + class StatusFilter(ChoiceSelect2Filter): + title = 'Status' + parameter_name = 'status' + autocomplete_choice_list = [ # list of choices + (1, 'Active',), + (2, 'Suspended',), + (3, 'Deleted',), + ] + + + @admin.register(Person) + class PersonAdmin(Select2AdminFilterMixin, admin.ModelAdmin): + + # change_list_template = 'admin/change_list_filter_sidebar.html' <- DON'T override change_list_template + list_filter = (CountryFilter, ProfessionFilter, StatusFilter,) # actually you cannot mix filters with traditional filters + + ``` + +## TODO + +* add tests +* add handling `dependent_fields` + +## Author + +* [Bartłomiej Żmudziński](https://github.com/bartekzmudzinski) + + + + +%package -n python3-django-select2-admin-filters +Summary: A simple extension to Django app to render filters in django admin panel as autocomplete widget. +Provides: python-django-select2-admin-filters +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-django-select2-admin-filters +## django_select2_admin_filters + +This extension is based on [django-select2](https://github.com/applegrew/django-select2) and works with or without Grappelli. + +## Installation + +* Install using pip + + ``` + pip install django-select2-admin-filters + ``` + +* Update INSTALLED_APPS, you need too put django_select2_admin_filters after admin and django_select2 + + ```python + INSTALLED_APPS = [ + 'django.contrib.admin', + # + 'django_select2', + 'django_select2_admin_filters', + ] + ``` + +* Update urls.py to use model filters (refer to [django-select2 documentation](https://django-select2.readthedocs.io/en/latest/get_started.html#installation)) + + ``` + path('select2/', include('django_select2.urls')), + ``` + +## Filters + +Filters are generally of two types, but each of them can be single or multiple selectable: +* ChoiceFilter + * ChoiceSelect2Filter + * MultipleChoiceSelect2Filter +* ModelFilter + * ModelSelect2Filter + * MultipleModelSelect2Filter + +## Usage + +* Use filter in your admin.py + ```python + from django.contrib import admin + from django_select2_admin_filters.admin import ( + Select2AdminFilterMixin) + from django_select2_admin_filters.filters import ( + ChoiceSelect2Filter, MultipleChoiceSelect2Filter, + ModelSelect2Filter, MultipleModelSelect2Filter) + from your_app.models import Country, Person, Profession + + + class CountryFilter(ModelSelect2Filter): + title = 'Country of residence' # filter's title + parameter_name = 'country' # parameter used in url and by default field name of Foreign Key used to filter results + autocomplete_queryset = Country.objects.all() # queryset to autocomplete + search_fields = ['name__icontains'] # fields of Country model used to filtering + + # optionally you can override queryset method + def queryset(self, request, queryset): + val = self.value() + if val: + return queryset.filter(country_of_residence=val) + return queryset + + + class ProfessionFilter(MultipleModelSelect2Filter): + title = 'Profession' + parameter_name = 'profession' + autocomplete_queryset = Profession.objects.all() + search_fields = ['name__icontains'] + + def queryset(self, request, queryset): + val = self.value_as_list() + if len(val) > 0: + return queryset.filter(professions__profession_id__in=val) + return queryset + + + class StatusFilter(ChoiceSelect2Filter): + title = 'Status' + parameter_name = 'status' + autocomplete_choice_list = [ # list of choices + (1, 'Active',), + (2, 'Suspended',), + (3, 'Deleted',), + ] + + + @admin.register(Person) + class PersonAdmin(Select2AdminFilterMixin, admin.ModelAdmin): + + # change_list_template = 'admin/change_list_filter_sidebar.html' <- DON'T override change_list_template + list_filter = (CountryFilter, ProfessionFilter, StatusFilter,) # actually you cannot mix filters with traditional filters + + ``` + +## TODO + +* add tests +* add handling `dependent_fields` + +## Author + +* [Bartłomiej Żmudziński](https://github.com/bartekzmudzinski) + + + + +%package help +Summary: Development documents and examples for django-select2-admin-filters +Provides: python3-django-select2-admin-filters-doc +%description help +## django_select2_admin_filters + +This extension is based on [django-select2](https://github.com/applegrew/django-select2) and works with or without Grappelli. + +## Installation + +* Install using pip + + ``` + pip install django-select2-admin-filters + ``` + +* Update INSTALLED_APPS, you need too put django_select2_admin_filters after admin and django_select2 + + ```python + INSTALLED_APPS = [ + 'django.contrib.admin', + # + 'django_select2', + 'django_select2_admin_filters', + ] + ``` + +* Update urls.py to use model filters (refer to [django-select2 documentation](https://django-select2.readthedocs.io/en/latest/get_started.html#installation)) + + ``` + path('select2/', include('django_select2.urls')), + ``` + +## Filters + +Filters are generally of two types, but each of them can be single or multiple selectable: +* ChoiceFilter + * ChoiceSelect2Filter + * MultipleChoiceSelect2Filter +* ModelFilter + * ModelSelect2Filter + * MultipleModelSelect2Filter + +## Usage + +* Use filter in your admin.py + ```python + from django.contrib import admin + from django_select2_admin_filters.admin import ( + Select2AdminFilterMixin) + from django_select2_admin_filters.filters import ( + ChoiceSelect2Filter, MultipleChoiceSelect2Filter, + ModelSelect2Filter, MultipleModelSelect2Filter) + from your_app.models import Country, Person, Profession + + + class CountryFilter(ModelSelect2Filter): + title = 'Country of residence' # filter's title + parameter_name = 'country' # parameter used in url and by default field name of Foreign Key used to filter results + autocomplete_queryset = Country.objects.all() # queryset to autocomplete + search_fields = ['name__icontains'] # fields of Country model used to filtering + + # optionally you can override queryset method + def queryset(self, request, queryset): + val = self.value() + if val: + return queryset.filter(country_of_residence=val) + return queryset + + + class ProfessionFilter(MultipleModelSelect2Filter): + title = 'Profession' + parameter_name = 'profession' + autocomplete_queryset = Profession.objects.all() + search_fields = ['name__icontains'] + + def queryset(self, request, queryset): + val = self.value_as_list() + if len(val) > 0: + return queryset.filter(professions__profession_id__in=val) + return queryset + + + class StatusFilter(ChoiceSelect2Filter): + title = 'Status' + parameter_name = 'status' + autocomplete_choice_list = [ # list of choices + (1, 'Active',), + (2, 'Suspended',), + (3, 'Deleted',), + ] + + + @admin.register(Person) + class PersonAdmin(Select2AdminFilterMixin, admin.ModelAdmin): + + # change_list_template = 'admin/change_list_filter_sidebar.html' <- DON'T override change_list_template + list_filter = (CountryFilter, ProfessionFilter, StatusFilter,) # actually you cannot mix filters with traditional filters + + ``` + +## TODO + +* add tests +* add handling `dependent_fields` + +## Author + +* [Bartłomiej Żmudziński](https://github.com/bartekzmudzinski) + + + + +%prep +%autosetup -n django-select2-admin-filters-0.1.4 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-django-select2-admin-filters -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.4-1 +- Package Spec generated @@ -0,0 +1 @@ +afdce7cc1e9b32b3ff9567eeb509fe77 django-select2-admin-filters-0.1.4.tar.gz |