app-generator / django-dynamic-datatb

Django Dynamic Datatables - Open-Source Library | AppSeed
https://pypi.org/project/django-dynamic-datatb/
MIT License
44 stars 19 forks source link

"Related Field has invalid lookup: icontains" #1

Closed pypv closed 1 year ago

pypv commented 1 year ago

Hello

Thank for the app, i couldn't make it work with my model, it seems like the app doesn't work with ForeignKey field or M2M fields

The issue appears in the view.py

for field in headings: filter_options = filter_options | Q(**{field + '__icontains': search_key})

i've tried to override the logic but couldn't make it run with my FK models

Thank you!

app-generator commented 1 year ago

Hello @pypv

Please attach a runtime log or provide the definition(s) that generate the errors.

Ty!

pypv commented 1 year ago

sure

`Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/datatb/country/

Django Version: 4.1.3 Python Version: 3.9.5 Installed Applications: ['django.contrib.admin', 'fx.apps.FragConfig', 'users.apps.UsersConfig', 'django.contrib.staticfiles', 'axes', 'registration', 'dal', 'dal_select2', 'crispy_forms', 'crispy_bootstrap5', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'data_wizard', 'data_wizard.sources', 'django_filters', 'import_export', 'taggit', 'formtools', 'ckeditor', 'mathfilters', 'django_extensions', 'widget_tweaks', 'debug_toolbar', 'rest_framework', 'rest_framework.authtoken', 'rest_framework_datatables_editor', 'admin_honeypot', 'django_dyn_dt']

Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', 'axes.middleware.AxesMiddleware']

Traceback (most recent call last): File "C:\fx\env\lib\site-packages\django\core\handlers\exception.py", line 55, in inner response = get_response(request) File "C:\fx\env\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "C:\fx\env\lib\site-packages\django_dyn_dt\views.py", line 47, in data_table_view all_data = model_class.objects.filter(filter_options) File "C:\fx\env\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, *kwargs) File "C:\fx\env\lib\site-packages\django\db\models\query.py", line 1420, in filter return self._filter_or_exclude(False, args, kwargs) File "C:\fx\env\lib\site-packages\django\db\models\query.py", line 1438, in _filter_or_exclude clone._filter_or_exclude_inplace(negate, args, kwargs) File "C:\fx\env\lib\site-packages\django\db\models\query.py", line 1445, in _filter_or_exclude_inplace self._query.add_q(Q(args, kwargs)) File "C:\fx\env\lib\site-packages\django\db\models\sql\query.py", line 1532, in addq clause, = self._add_q(q_object, self.used_aliases) File "C:\fx\env\lib\site-packages\django\db\models\sql\query.py", line 1562, in _add_q child_clause, needed_inner = self.build_filter( File "C:\fx\env\lib\site-packages\django\db\models\sql\query.py", line 1388, in build_filter return self._add_q( File "C:\fx\env\lib\site-packages\django\db\models\sql\query.py", line 1562, in _add_q child_clause, needed_inner = self.build_filter( File "C:\fx\env\lib\site-packages\django\db\models\sql\query.py", line 1478, in build_filter condition = self.build_lookup(lookups, col, value) File "C:\fx\env\lib\site-packages\django\db\models\sql\query.py", line 1292, in build_lookup raise FieldError(

Exception Type: FieldError at /datatb/country/ Exception Value: Related Field got invalid lookup: icontains `

app-generator commented 1 year ago

Hello @pypv

Sorry for this late reply. The issue is now fixed in the latest version. In case you want a fully configured project, here is one:

Let us know if you need further assistance: https://appseed.us/support/

app-generator commented 1 year ago

Closing.