Skip to content

Commit

Permalink
feat: autocomplete filters (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav authored Jan 30, 2025
1 parent 43e7390 commit cd448eb
Show file tree
Hide file tree
Showing 21 changed files with 1,006 additions and 643 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Have you decided to start using Unfold but don’t have time to make the switch
- **Sidebar:** Simplifies the creation of sidebar navigation with icons, collapsibles, and more.
- **Dark mode:** Supports both light and dark mode versions.
- **Actions:** Offers multiple ways to define actions within different parts of the admin interface.
- **Filters:** Custom dropdowns, numeric, datetime, and text fields.
- **Filters:** Custom dropdowns, autocomplete, numeric, datetime, and text fields.
- **Dashboard:** Includes helpers for creating custom dashboard pages.
- **Components:** Reusable UI components such as cards, buttons, and charts.
- **WYSIWYG widget:** Built-in support for WYSIWYG (Trix).
Expand Down
37 changes: 37 additions & 0 deletions docs/filters/autocomplete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Autocomplete filter
order: 5
description: Autocomplete filters for changelist view.
---

# Autocomplete filters

Unfold provides two different types of autocomplete filters: `AutocompleteSelectFilter` and `AutocompleteSelectMultipleFilter`. Both of them are implemented in `unfold.contrib.filters` so make sure this app is in your `INSTALLED_APPS` in `settings.py`.

All the referenced fields must be `ForeignKey` or `ManyToManyField` fields and the same time the referenced admin model must have defined `search_fields` attribute otherwise the application will raise an error.

```python
# admin.py

from django.contrib import admin
from django.contrib.auth.models import User

from unfold.admin import ModelAdmin
from unfold.contrib.filters.admin import (
AutocompleteSelectFilter,
AutocompleteSelectMultipleFilter
)

@admin.register(User)
class YourModelAdmin(ModelAdmin):
list_filter = (
# Autocomplete filter
["other_model_field", AutocompleteSelectFilter],

# Autocomplete multiple filter
["other_multiple_model_field", AutocompleteSelectMultipleFilter],
)

class OtherModelAdmin(ModelAdmin):
search_fields = ["name"]
```
Loading

0 comments on commit cd448eb

Please sign in to comment.