Browse Source

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

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

5
adminpanel/settings.py

@ -31,6 +31,7 @@ ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django_admin_listfilter_dropdown',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
@ -38,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'adminpanelapp',
'rangefilter',
]
MIDDLEWARE = [
@ -114,7 +116,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATIC_URL = '/static/'
# Default primary key field type
# 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'
ASYNC_MODE = 'django'

3
adminpanel/urls.py

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

17
adminpanelapp/admin.py

@ -1,12 +1,13 @@
from datetime import timedelta, datetime
from django.contrib.auth.models import User, Group
from django.http import HttpResponseRedirect
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.utils.safestring import mark_safe
from django_admin_listfilter_dropdown.filters import DropdownFilter
from .models import Orders, Users
from django.contrib import admin, messages
from django.urls import reverse
from rangefilter.filters import DateRangeFilter
class OrdersAdmin(admin.ModelAdmin):
@ -16,6 +17,18 @@ class OrdersAdmin(admin.ModelAdmin):
)
actions = ['send_message']
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):

2
requirements.txt

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