Browse Source

добиавл фильтры и поиск с поддержкой regex #10

adminpanel_filters
Anton 1 year ago
parent
commit
33813c2bf5
  1. 5
      adminpanel/settings.py
  2. 3
      adminpanel/urls.py
  3. 19
      adminpanelapp/admin.py
  4. 2
      requirements.txt

5
adminpanel/settings.py

@ -31,6 +31,7 @@ ALLOWED_HOSTS = ['*']
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'django_admin_listfilter_dropdown',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
@ -38,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'adminpanelapp', 'adminpanelapp',
'rangefilter',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -114,7 +116,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/ # https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = '/static/'
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
@ -123,3 +125,4 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
ASGI_APPLICATION = 'adminpanelapp.asgi.application' ASGI_APPLICATION = 'adminpanelapp.asgi.application'
ASYNC_MODE = 'django' ASYNC_MODE = 'django'

3
adminpanel/urls.py

@ -1,8 +1,7 @@
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.views.generic import RedirectView from django.views.generic import RedirectView
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),

19
adminpanelapp/admin.py

@ -1,21 +1,34 @@
from datetime import timedelta, datetime
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django_admin_listfilter_dropdown.filters import DropdownFilter
from .models import Orders, Users from .models import Orders, Users
from django.contrib import admin, messages from django.contrib import admin, messages
from django.urls import reverse from django.urls import reverse
from rangefilter.filters import DateRangeFilter
class OrdersAdmin(admin.ModelAdmin): class OrdersAdmin(admin.ModelAdmin):
list_display = ( list_display = (
'orderName', 'orderCreateDateTime', 'orderDesc', 'orderAddress', 'orderName', 'orderCreateDateTime', 'orderDesc', 'orderAddress',
'catID', 'userName', 'orderStatus', 'show_photo', 'show_photopay', 'catID', 'userName', 'orderStatus', 'show_photo', 'show_photopay',
) )
actions = ['send_message'] actions = ['send_message']
exclude = ['orderAccess', 'userID', 'orderPhoto', 'orderPhotoPay'] exclude = ['orderAccess', 'userID', 'orderPhoto', 'orderPhotoPay']
search_fields = ['orderName__regex', 'orderCreateDateTime__regex', 'orderDesc__regex',
'orderAddress__regex', 'catID__regex', 'orderStatus__regex'
]
list_filter = [
('orderName', DropdownFilter),
('orderAddress', DropdownFilter),
('orderDesc', DropdownFilter),
('catID', DropdownFilter),
('orderCreateDateTime', DateRangeFilter)
]
def userName(self, obj): def userName(self, obj):

2
requirements.txt

@ -5,3 +5,5 @@ Django==2.2.1
python-dotenv==0.21.1 python-dotenv==0.21.1
requests==2.31.0 requests==2.31.0
urllib3==1.25.11 urllib3==1.25.11
django-admin-list-filter-dropdown==1.0.3
django-admin-rangefilter==0.11.2
Loading…
Cancel
Save