Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django-filters prevents django admin app from starting #1694

Closed
rmunoz10 opened this issue Nov 13, 2024 · 1 comment
Closed

django-filters prevents django admin app from starting #1694

rmunoz10 opened this issue Nov 13, 2024 · 1 comment

Comments

@rmunoz10
Copy link

Hello,

Trying to add django-filters to my django admin app. App works without filter. But runserver errors out with "The value of 'list_filter[0]' must inherit from 'ListFilter'." when I add "list_filter = (SfAccountFilter,)" to admin.py. See below for details

Not sure what I'm missing

I would appreciate any insight

Thanks


admin.py

from django.contrib import admin

Register your models here.

from .models import SfAccountHierarchy
from .filters import SfAccountFilter

Define the admin class

class SfAccountHierarchyAdmin(admin.ModelAdmin):
list_filter = (SfAccountFilter,)

Register the admin class with the associated model

admin.site.register(SfAccountHierarchy, SfAccountHierarchyAdmin)


filters.py

import django_filters
from .models import SfAccountHierarchy

class SfAccountFilter(django_filters.FilterSet):
account_nm = django_filters.CharFilter(lookup_expr='icontains', label='Account Name')
class Meta:
model = SfAccountHierarchy
fields = ['account_nm']


models.py

from django.db import models

Create your models here.

from django.urls import reverse # Used in get_absolute_url() to get URL for specified ID

class SfAccountHierarchy(models.Model):
id = models.CharField(primary_key=True, max_length=30, help_text='Account ID')
account_nm = models.CharField(max_length=60)
master_parentid = models.CharField(blank=True, null=True, max_length=30)
master_account_nm = models.CharField(blank=True, null=True, max_length=60)
parentid = models.CharField(blank=True, null=True, max_length=30)
parent_account_nm = models.CharField(blank=True, null=True, max_length=30)
account_nm_alias = models.CharField(blank=True, null=True, max_length=60)
parent_account_nm_alias = models.CharField(blank=True, null=True, max_length=60)

class Meta:
    managed = False
    db_table = 'sf_account_hierarchy'


def __str__(self):
    return self.id


def get_absolute_url(self):
    """Returns the URL to access a detail record for this account."""
    return reverse('account-detail', args=[str(self.id)])

settings.py

...

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_filters', # Add django-filter
'catalog', # Add your app
]


Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/rmunoz/dev/my_django_project/venv/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/rmunoz/dev/my_django_project/venv/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 134, in inner_run
self.check(display_num_errors=True)
File "/home/rmunoz/dev/my_django_project/venv/lib/python3.10/site-packages/django/core/management/base.py", line 563, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
<class 'catalog.admin.SfAccountHierarchyAdmin'>: (admin.E113) The value of 'list_filter[0]' must inherit from 'ListFilter'.

System check identified 1 issue (0 silenced).

@carltongibson
Copy link
Owner

Django Filter's filters are not the same thing as admin filters. You need to use those:

https://docs.djangoproject.com/en/5.1/ref/contrib/admin/filters/

@carltongibson carltongibson closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants