Reputation: 2196
let's say I have an employee model with the field username which can be selected. Usually in admin > employee page, we will see a dropdown of a list of employee username but instead of doing that, is it possible to have like a select list and on top of that there's a filter so it'll be easier to find what is needed instead of scrolling through the whole dropdown if there are like hundreds....
an example of what I want is like this....
so in the box it'll be like list of the employee's name so I can click and choose whichever needed and also use filter to find the username.
this image is actually cropped from admin > users
Thanks in advance for any suggestions.
Upvotes: 0
Views: 211
Reputation: 4643
This is auto generate form input when there is manytoMany relation in your model.
Fox ex, something like this.
class Team(models.Model):
members= models.ManyToManyField(Employee)
In you admin.py you have to register your model to show in admin pages.
class TeamAdmin(admin.ModelAdmin):
filter_horizontal = ('employees',)
admin.site.register(Team, TeamAdmin)
There is more evolved selection also possibly with some customisation.
Upvotes: 1