How to add a filtersearch option to a foreign key dropdown in Wagtail admin? - Stack Overflow

admin2025-04-20  0

I have a Django foreign key field in my Wagtail admin panel that references the Faculty model. However, when selecting a faculty for a course, the dropdown list does not provide a search or filter option.

Current code:

faculty = models.ForeignKey("Faculty", on_delete=models.CASCADE, related_name="courses") FieldPanel("faculty"),

This generates a basic dropdown list in the Wagtail admin panelbasic, but I need a searchable dropdown like this: need like this

What I need

A filter/search feature in the dropdown list when selecting a faculty in Wagtail admin.

Preferably a select2-style search box or any built-in Wagtail solution.

What I tried:

I looked into using FieldPanel, but I’m not sure how to make it searchable. Should I use AutocompletePanel, or is there another approach?

Any help would be appreciated!

I have a Django foreign key field in my Wagtail admin panel that references the Faculty model. However, when selecting a faculty for a course, the dropdown list does not provide a search or filter option.

Current code:

faculty = models.ForeignKey("Faculty", on_delete=models.CASCADE, related_name="courses") FieldPanel("faculty"),

This generates a basic dropdown list in the Wagtail admin panelbasic, but I need a searchable dropdown like this: need like this

What I need

A filter/search feature in the dropdown list when selecting a faculty in Wagtail admin.

Preferably a select2-style search box or any built-in Wagtail solution.

What I tried:

I looked into using FieldPanel, but I’m not sure how to make it searchable. Should I use AutocompletePanel, or is there another approach?

Any help would be appreciated!

Share Improve this question asked Mar 3 at 2:25 pavipavi 131 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

If you register your Faculty model as a snippet, FieldPanel will load the Snippet Chooser, which has a search box. You can then tweak the search by specifying the search fields and autocomplete fields for the Faculty model.

This is how the chooser looks like:

See Registering snippets and Making snippets searchable

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745112194a285648.html

最新回复(0)