djblets.db.fields.comma_separated_values_field¶
Database field for storing comma-separated values.
New in version 5.0.
- class CommaSeparatedValuesField(*args, db_collation=None, **kwargs)[source]¶
Bases:
CharField
Database field for storing comma-separated values.
This field wraps a comma-separated list of values, helping translate between Python lists of strings and the stored string.
Items in the list are expected to be simple values, and must not contain a comma (
,
).The following methods are made available on the model containing the field:
- MyModel.get_<fieldname>_list() -> Sequence[str]
Return a list of display names for all items.
If this field was set up with a
choices=
parameter, the choice display names will be used to represent each item in the list. If not, or if a choice is not present, the respective item’s string representation will be used instead.New in version 5.2.
- MyModel.get_<fieldname>_display() -> str
Return a string display representation of the items.
This will return a string containing a comma-separated list of display names for all values in the field.
New in version 5.2.
Changed in version 5.2:
get_<fieldname>_list()
andget_<fieldname>_display()
methods are now added to the model.New in version 5.0.
- contribute_to_class(cls: type[django.db.models.base.Model], name: str, *args, **kwargs) None [source]¶
Add methods to the model.
This will add the
get_fieldname_list()
andget_fieldname_display()
methods to the model.New in version 5.2.
- from_db_value(value: Optional[str], *args) Optional[list[str]] [source]¶
Convert the value coming from the database.
- to_python(value: Union[str, list]) list[str] [source]¶
Convert the given value from DB representation to Python.
- get_prep_value(value: Optional[list[str]]) str [source]¶
Convert the given Python representation to DB format.
- get_db_prep_value(value: Union[list[str], str, None], connection: BaseDatabaseWrapper, prepared: bool = False) str [source]¶
Return the prepared value for saving to the database.
- value_to_string(obj: Model) str [source]¶
Return the value as a string.
- Parameters:
obj (
django.db.models.Model
) – The model that this field is a part of.- Returns:
A string representation of the field contents.
- Return type:
- get_default() :py:class:`list` [source]¶
Return the default value for the field.
- Returns:
The default value for the field.
- Return type:
- __annotations__ = {}¶