Registry / web-framework / django-multiselectfield

django-multiselectfield

JSON →
library1.0.1pypypi✓ verified 28d ago

django-multiselectfield provides new model and form fields for Django, allowing users to select multiple options from a predefined list. The selected values are stored in the database as a CharField containing comma-separated values. The current version is 1.0.1, and the project has an irregular release cadence, with a significant 1.0.0 release in June 2025 that introduced breaking changes.

pip install django-multiselectfield
INSTALL
IMPORT
SIG · DJANGO-MULTISELECT
D
django-multiselectfield
web-frameworkpythonv1.0.1
Install
3.5s avg
Import
689ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.732s · 66.5MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.5s · import 0.646s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MultiSelectField
✓ from multiselectfield import MultiSelectField
Used for creating model fields that allow multiple selections.
SortMultiSelectField
✓ from multiselectfield import SortMultiSelectField
Introduced in v1.0.0 for sortable multi-select fields; requires jQuery and jQuery UI.

To use `MultiSelectField`, define your choices as a tuple of tuples. Add `multiselectfield` to your `INSTALLED_APPS` and then define a model field using `MultiSelectField`. Remember to run `makemigrations` and `migrate`.

from django.db import models from multiselectfield import MultiSelectField # In your settings.py, ensure 'multiselectfield' is in INSTALLED_APPS # INSTALLED_APPS = [ # # ... # 'multiselectfield', # # ... # ] MY_CHOICES = ( ('item_key1', 'Item title 1.1'), ('item_key2', 'Item title 1.2'), ('item_key3', 'Item title 1.3'), ('item_key4', 'Item title 1.4'), ('item_key5', 'Item title 1.5') ) class MyModel(models.Model): my_field = MultiSelectField(choices=MY_CHOICES, default=['item_key1', 'item_key5']) my_field_with_limits = MultiSelectField( choices=MY_CHOICES, min_choices=2, max_choices=3, max_length=100 # Adjust max_length based on expected comma-separated string length ) def __str__(self): return f"{self.my_field} - {self.my_field_with_limits}" # After defining your model, run: # python manage.py makemigrations # python manage.py migrate
Debug
Known issues
breakingVersion 1.0.0 removed `MSFList` and `MSFFlatchoices`. These classes were intended for `admin.list_display` but never functioned correctly.
fix
Remove any references to `MSFList` or `MSFFlatchoices` from your code. If you were using them for `list_display`, consider using `get_FOO_display` method on your model or a custom admin method.
affects: >=1.0.0
breakingAs of version 1.0.0, integer choices are no longer supported. `MultiSelectField` inherits from `CharField`, and it's impossible to reliably distinguish between integer `1` and string `'1'` upon retrieval from the database.
fix
Ensure all choices provided to `MultiSelectField` are string-based. For example, use `(('1', 'Item 1'), ('2', 'Item 2'))` instead of `((1, 'Item 1'), (2, 'Item 2'))`.
affects: >=1.0.0
gotchaAdding a `MultiSelectField` directly to `list_display` in Django admin might not render as expected (e.g., showing a raw comma-separated string).
fix
Use a custom method on your `ModelAdmin` or the `get_FOO_display` method on your model to format the output for `list_display`. Example: `list_display = ('get_my_field_display',)` in `ModelAdmin` where `get_my_field_display` is a method on the model.
affects: All
gotchaThe `SortMultiSelectField` (introduced in v1.0.0) requires jQuery and jQuery UI to function correctly in the browser. These libraries are typically included in the Django admin interface.
fix
Ensure jQuery and jQuery UI are loaded in your templates when using `SortMultiSelectField` outside of the default Django admin forms. In the admin, you might need to explicitly include them in your `ModelAdmin`'s `form` definition or `change_form.html`.
affects: >=1.0.0
gotchaAs a `CharField` subclass, `MultiSelectField` stores values as comma-separated strings. Avoid setting `null=True` on `CharField`s in Django, as it's generally recommended to use `blank=True` and `default=''` for string-based fields.
fix
Use `blank=True, default=''` instead of `null=True` for `MultiSelectField` if the field is optional.
affects: All
Errors
Common errors & fixes
ValueError: invalid literal for int() with base 10: '<value>'
This error occurs when the choices for `MultiSelectField` are defined as integers, but the values received from a form (e.g., from POST data) are strings that cannot be directly converted to integers.
fix
Ensure that the choices defined for `MultiSelectField` in your model use string keys, even if they represent numerical values, or explicitly convert the incoming string values to integers before validation if integer choices are strictly necessary and handled correctly throughout the application. For example, use `(('1', 'Item 1'), ('2', 'Item 2'))` instead of `((1, 'Item 1'), (2, 'Item 2'))` in your `MY_CHOICES` tuple.
Select a valid choice. <value> is not one of the available choices.
This Django `ValidationError` occurs when the submitted values for a `MultiSelectField` do not exactly match the predefined choices, often due to dynamic choices not being correctly updated in the form's `choices` attribute or an issue with how the selected data is passed back.
fix
Ensure that the choices provided to the `MultiSelectField` in your form or model match the values being submitted. If using dynamic choices, update the `choices` attribute of the field in the form's `__init__` method, or verify that the selected values are being passed as a list of valid keys.
AttributeError: 'list' object has no attribute 'split'
This error arises when code attempts to call the `split()` method on a Python list object, but `split()` is a string method. This typically happens when data from `MultiSelectField` (which is stored as a comma-separated string) is already converted into a list, and further processing incorrectly assumes it's still a string.
fix
Identify where the object becomes a list instead of a string. If you need to process individual items, iterate over the list directly. If you expect a string, ensure that the data type is indeed a string before calling `split()` (e.g., by converting it back to a string with `','.join(my_list)` if it was a list of items to be split).
AttributeError: 'super' object has no attribute '_get_flatchoices'
This specific error indicates an incompatibility between `django-multiselectfield` and Django 5.0+ because Django's internal `CharField` (which `MultiSelectField` inherits from) no longer has the `_get_flatchoices` method; instead, `flatchoices` is directly available.
fix
Update to a version of `django-multiselectfield` that officially supports Django 5.0+. If an updated version is not available, a common workaround involves commenting out the problematic `_get_flatchoices` property definition in the `multiselectfield/db/fields.py` file, as the functionality is directly provided by Django 5.0+.
Upgrade
Version history
1.0.1latest on PyPI · released Jun 12, 2025
Audit
Dependencies
DjangorequiredThis is a Django app, requiring Django 3.2+ for full compatibility.
Agent activity
9 hits · last 30 days
node
8
Resources
django-multiselectfield — pip install django-multiselectfield · libregistry