-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43e7390
commit cd448eb
Showing
21 changed files
with
1,006 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
``` |
Oops, something went wrong.