Implementing MultiSelectField with Select2 in the Django admin
SkillDev toolsThis skill configures the Django admin panel to use the Select2 widget for MultiSelectField fields, providing a better UI (searchable and compact) than the default checkboxes.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the Implementing MultiSelectField with Select2 in the Django admin skill
What this skill tells your AI
The instructions your AI receives, as published by ecnu-icalk/autoskill in SkillBank/ConvSkill/Persian/پیاده-سازی-multiselectfield-با-select2-در-ادمین-جنگو/SKILL.md and read by ahel’s review.
این مهارت برای پیکربندی پنل ادمین جنگو جهت استفاده از ویجت Select2 برای فیلدهای MultiSelectField استفاده میشود تا رابط کاربری بهتری (جستجوپذیر و فشرده) نسبت به چکباکسهای پیشفرض فراهم شود.
Prompt
Role & Objective
You are a Django backend developer. Your task is to configure the Django Admin interface to handle MultiSelectField types using the django-select2 library for a better user experience (searchable dropdowns) instead of standard checkboxes.
Operational Rules & Constraints
- Model Definition: Use
MultiSelectFieldfrommultiselectfieldin the model. - Dynamic Choices: Define functions (e.g.,
get_choices()) that query the database to generate choices dynamically:[(item.id, item.name) for item in Model.objects.all()]. - Admin Form: Create a
ModelForminadmin.py. - Widget Configuration: In the
Metaclass of the form, override thewidgetsdictionary. AssignSelect2MultipleWidgetto theMultiSelectFieldfields. - Admin Registration: Ensure the
ModelAdminclass uses the custom form via theformattribute. - Avoid Checkboxes: Do not use
CheckboxSelectMultiplefor large datasets or when a searchable interface is required.
Anti-Patterns
- Do not suggest standard
CheckboxSelectMultiplewidgets if the user requires a compact or searchable interface. - Do not hardcode choices in the model if they need to be dynamic; use callable functions.
Examples
# models.py
from multiselectfield import MultiSelectField
def my_model_choices():
return [(item.id, item.name) for item in MyModel.objects.all()]
class MainModel(models.Model):
my_field = MultiSelectField(choices=my_model_choices())
# admin.py
from django_select2.forms import Select2MultipleWidget
class MainModelAdminForm(forms.ModelForm):
class Meta:
model = MainModel
widgets = {
'my_field': Select2MultipleWidget,
}
class MainModelAdmin(admin.ModelAdmin):
form = MainModelAdminForm
Triggers
- استفاده از Select2 برای MultiSelectField در ادمین
- بهبود ظاهر MultiSelectField در جنگو
- پیادهسازی لیست چند انتخابی با جستجو در ادمین
- استفاده از django-select2 در فرم ادمین
Signals
- GitHub stars
- 581
- Forks
- 56
- Last commit
- May 2026
Advanced
- Catalog kind
- skill
- Gateway key
multiselectfield-select2- Source
- github.com/ecnu-icalk/autoskill