Проблемы с DateRangeFilter
при использовании фильтра по произвольному диапазону дат выдает ошибку
AttributeError at /admin/manufactory/employeeworklog/
'list' object has no attribute 'strip'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/manufactory/employeeworklog/?date__range__gte=01.12.2024&date__range__lte=07.01.2025
Django Version: 5.1.1
Exception Type: AttributeError
Exception Value:
'list' object has no attribute 'strip'
Exception Location: C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\fields.py, line 462, in to_python
Raised during: django.contrib.admin.options.changelist_view
Python Executable: C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Scripts\python.exe
Python Version: 3.11.9
Python Path:
['C:\\Users\\ulukm\\Downloads\\ERP_Textile',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\python311.zip',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\DLLs',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\Lib',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0',
'C:\\Users\\ulukm\\Documents\\projects\\ERP_Textile\\venv',
'C:\\Users\\ulukm\\Documents\\projects\\ERP_Textile\\venv\\Lib\\site-packages']
Server time: Thu, 16 Jan 2025 16:46:20 +0600
Traceback (most recent call last):
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\options.py", line 718, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 188, in _view_wrapper
result = _process_exception(request, e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 186, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\views\decorators\cache.py", line 80, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\sites.py", line 241, in inner
return view(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\import_export\admin.py", line 553, in changelist_view
return super().changelist_view(request, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\import_export\admin.py", line 779, in changelist_view
return super().changelist_view(request, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\import_export\admin.py", line 65, in changelist_view
return super().changelist_view(request, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 48, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 188, in _view_wrapper
result = _process_exception(request, e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 186, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\options.py", line 2121, in changelist_view
media = self.media + formset.media
^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\formsets.py", line 521, in media
if self.forms:
^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\functional.py", line 47, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\formsets.py", line 207, in forms
for i in range(self.total_form_count())
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\formsets.py", line 182, in total_form_count
initial_forms = self.initial_form_count()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\models.py", line 697, in initial_form_count
return len(self.get_queryset())
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\models\query.py", line 382, in __len__
self._fetch_all()
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\models\query.py", line 1928, in _fetch_all
self._result_cache = list(self._iterable_class(self))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\models\query.py", line 91, in __iter__
results = compiler.execute_sql(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\models\sql\compiler.py", line 1574, in execute_sql
cursor.execute(sql, params)
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\backends\utils.py", line 122, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\backends\utils.py", line 79, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\backends\utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\backends\utils.py", line 100, in _execute
with self.db.wrap_database_errors:
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 354, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: no such column: manufactory_operationlog.quantity
[16/Jan/2025 16:43:53] "GET /admin/manufactory/operationlog/ HTTP/1.1" 500 229141
[16/Jan/2025 16:46:09] "GET /admin/ HTTP/1.1" 200 170904
[16/Jan/2025 16:46:16] "GET /admin/manufactory/employeeworklog/ HTTP/1.1" 200 141413
[16/Jan/2025 16:46:17] "GET /static/admin/js/calendar.js?_=1737024377120 HTTP/1.1" 200 9141
[16/Jan/2025 16:46:17] "GET /static/admin/js/admin/DateTimeShortcuts.js?_=1737024377121 HTTP/1.1" 200 19319
Internal Server Error: /admin/manufactory/employeeworklog/
Traceback (most recent call last):
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\options.py", line 718, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 188, in _view_wrapper
result = _process_exception(request, e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 186, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\views\decorators\cache.py", line 80, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\sites.py", line 241, in inner
return view(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 48, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 188, in _view_wrapper
result = _process_exception(request, e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\utils\decorators.py", line 186, in _view_wrapper
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\options.py", line 2001, in changelist_view
cl = self.get_changelist_instance(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\options.py", line 866, in get_changelist_instance
return ChangeList(
^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\views\main.py", line 145, in __init__
self.queryset = self.get_queryset(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\contrib\admin\views\main.py", line 553, in get_queryset
new_qs = filter_spec.queryset(request, qs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\rangefilter\filters.py", line 145, in queryset
if self.form.is_valid():
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\forms.py", line 197, in is_valid
return self.is_bound and not self.errors
^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\forms.py", line 192, in errors
self.full_clean()
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\forms.py", line 325, in full_clean
self._clean_fields()
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\forms.py", line 333, in _clean_fields
self.cleaned_data[name] = field._clean_bound_field(bf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\fields.py", line 266, in _clean_bound_field
return self.clean(value)
^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\fields.py", line 204, in clean
value = self.to_python(value)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\fields.py", line 493, in to_python
return super().to_python(value)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ulukm\Documents\projects\ERP_Textile\venv\Lib\site-packages\django\forms\fields.py", line 462, in to_python
value = value.strip()
^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'strip'
[16/Jan/2025 16:46:20] "GET /admin/manufactory/employeeworklog/?date__range__gte=01.12.2024&date__range__lte=07.01.2025 HTTP/1.1" 500 180803
admin.py
from rangefilter.filters import DateRangeFilter
@admin.register(EmployeeWorkLog)
class EmployeeWorkLogAdmin(admin.ModelAdmin):
list_display = ('employee', 'order', 'operation', 'date', 'quantity', 'piece_rate', 'total_cost')
list_filter = ('employee', 'order', 'operation', ('date', DateRangeFilter),)
search_fields = ('employee__name', 'order__order_number', 'operation__operation__name')
readonly_fields = ('total_cost',)
date_hierarchy = 'date'
fieldsets = (
(None, {'fields': ('employee', 'order', 'operation', 'date', 'quantity', 'piece_rate')}),
('Рассчитанные данные', {'fields': ('total_cost',)}),
)
def get_readonly_fields(self, request, obj=None):
if obj:
return [field.name for field in self.model._meta.fields]
return []