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

Show in list_filter the Product selector #1378

Open
paulocoutinhox opened this issue Nov 28, 2024 · 0 comments
Open

Show in list_filter the Product selector #1378

paulocoutinhox opened this issue Nov 28, 2024 · 0 comments

Comments

@paulocoutinhox
Copy link

paulocoutinhox commented Nov 28, 2024

Hi,

I tried a lot here and chatgpt build a filter in list_filter that is a product selector.

In the admin form it works without problems:

widgets = {
            "category": autocomplete.ModelSelect2(
                url="site-category-autocomplete",
            ),
            "subcategory": autocomplete.ModelSelect2(
                url="site-subcategory-autocomplete",
                forward=["category"],
            ),
            "product": autocomplete.ModelSelect2(
                url="product-autocomplete",
                forward=["product"],
            ),
}

But in list_filter it show nothing:

image

My code:

class AuctionAdmin(ReadonlyLinksMixin, admin.ModelAdmin):
    list_filter = [
        ("category", CategoryFilter),
        ("subcategory", SubcategoryFilter),
        ("supplier", RelatedDropdownFilter),
        ProductFilter,
        "status",
    ]
from dal import autocomplete
from django_admin_listfilter_dropdown.filters import RelatedDropdownFilter


class ProductFilter(RelatedDropdownFilter):
    def field_choices(self, field, request, model_admin):
        # Aqui não retorna nada, pois usamos o autocomplete no widget
        return []

    def widget(self, field, request):
        return autocomplete.ModelSelect2(
            url='product-autocomplete',
            attrs={
                'data-placeholder': 'Search for a product...',
                'data-minimum-input-length': 1,  # Ativa a pesquisa após um caractere
            }
        )

Can someone help me?

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

1 participant