Skip to main content

🧩 Widgets

Every field on the edit page is edited with a widget. Content Studio picks the widget from the field's type, so most models need no configuration.

Default widgets​

Field typeWidget
CharField and number fieldsInputWidget
SlugFieldSlugWidget
TextFieldTextAreaWidget
BooleanFieldCheckboxWidget
ForeignKey, OneToOneFieldForeignKeyWidget
ManyToManyFieldManyToManyWidget
DateField, DateTimeField, TimeFieldDateWidget, DateTimeWidget, TimeWidget
JSONFieldJSONWidget
HTMLField (built-in)RichTextWidget
TagField (built-in)TagWidget
FlexField (built-in)JSONSchemaWidget
MultipleChoiceField (built-in)MultiSelectWidget
URLPathField (built-in)URLPathWidget
MediaField, ManyMediaField (built-in)MediaWidget, ManyMediaWidget
AutoSlugField (django-extensions)SlugWidget

Fields with choices get a select. Fields of other types get a plain input.

Two widgets are not used by default but are there to choose:

  • SwitchWidget: a toggle switch, for a BooleanField.
  • ToggleGroupWidget: a row of buttons for a field with choices, of which exactly one is active.

Use another widget for one field​

Pass a widget class to a Field in edit_main or edit_sidebar:

# blog/admin.py
from content_studio import register, widgets
from content_studio.admin import ModelStudio
from content_studio.form import Field, FormSet

from .models import Article


@register(Article)
class ArticleStudio(ModelStudio):
edit_main = [
FormSet(
fields=[
"title",
Field("featured", widget=widgets.SwitchWidget),
],
),
]

The widget only changes how the field is edited. Read-only fields keep showing their value through its format.

Change the default for a field type​

To change the widget for every field of a type, extend the site's default_widget_mapping:

# mysite/studio.py
from django.db import models

from content_studio import widgets
from content_studio.admin import ContentStudioSite


class BlogStudioSite(ContentStudioSite):
default_widget_mapping = {
**ContentStudioSite.default_widget_mapping,
models.EmailField: widgets.InputWidget,
}


admin_site = BlogStudioSite()

Formats​

Values on the list page and in read-only fields are shown through formats: dates, times, booleans, numbers, tags, rich text and media each have one. The site's default_format_mapping maps field types to formats, and you change it the same way as default_widget_mapping.

Custom widgets and formats​

Only the built-in widgets and formats are supported. The admin has no way to show a widget or format class of your own.