Fields
Full attribute and method reference for BaseField and every built-in field type, generated
from their docstrings. For a task-oriented walkthrough, see Fields.
Base class
starlette_admin.fields.BaseField
dataclass
The base configuration class for all model fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The field's name, which must match the attribute name in your model. |
required |
label
|
str | None
|
A human-readable label used for display purposes. |
None
|
help_text
|
str | None
|
An optional hint or description to display within forms. |
None
|
type
|
str | None
|
The unique identifier for the field's type. |
None
|
disabled
|
bool | None
|
If |
False
|
read_only
|
bool | None
|
If |
False
|
default
|
Any | None
|
The default value used to prefill the field on creation forms. This can be a static value or a callable that accepts zero or one positional argument (the current request). |
None
|
getter
|
Getter | None
|
|
None
|
formatter
|
dict[RequestAction, Formatter] | None
|
Maps a [RequestAction][starlette_admin.types.RequestAction] to a
|
None
|
parser
|
dict[RequestAction, Parser] | None
|
Maps a [RequestAction][starlette_admin.types.RequestAction] to a
|
None
|
id
|
str
|
A unique identifier for the field instance. |
''
|
filters
|
list[type[BaseFilter]] | None
|
An explicit override for the list page filters available for this
field. If |
None
|
required
|
bool | None
|
If |
False
|
validators
|
list[Validator]
|
Callables |
list()
|
exclude_from_list
|
bool | None
|
If |
False
|
exclude_from_detail
|
bool | None
|
If |
False
|
exclude_from_create
|
bool | None
|
If |
False
|
exclude_from_edit
|
bool | None
|
If |
False
|
exclude_from_export
|
bool | None
|
If |
False
|
exclude_from_import
|
bool | None
|
If |
False
|
searchable
|
bool | None
|
If |
True
|
orderable
|
bool | None
|
If |
True
|
inline_editable
|
bool | None
|
If |
False
|
copy_to_clipboard
|
bool | None
|
If |
False
|
list_template
|
str
|
The template path used to render this field in the list view. |
'fields/list/text.html'
|
form_template
|
str
|
The template path used to render this field in create/edit forms. |
'fields/form/input.html'
|
detail_template
|
str
|
The template path used to render this field in the detail view. |
'fields/detail/text.html'
|
null_template
|
str
|
The template path used to render this field when its value is |
'fields/detail/_null.html'
|
empty_template
|
str
|
The template path used to render this field when its value is an empty list or tuple, in both the list and detail views. |
'fields/detail/_empty.html'
|
extra
|
dict[str, Any] | None
|
A dictionary for storing custom metadata. Starlette-admin neither reads nor writes to this dictionary. It is provided solely as a convenience for developers to attach arbitrary data to a field (e.g., to access within custom templates or BaseAdmin hooks) without needing to subclass the field. |
None
|
Source code in starlette_admin/fields.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
additional_css_links(request)
additional_js_links(request)
dict()
get_create_default(request)
async
Return the value that should be used to prefill this field on the create form.
default may be:
- a static value (e.g.
default="hello"), - a callable that takes no arguments (e.g.
default=datetime.now), - a callable that takes the current request as its only argument
(e.g.
default=lambda request: request.user.locale).
Subclasses may override this method to coerce the default into the shape expected by their form templates.
Source code in starlette_admin/fields.py
input_params()
parse_form_data(request, form_data)
async
Extracts the value of this field from submitted form data.
Source code in starlette_admin/fields.py
parse_import_value(request, value)
async
Parse a raw cell value from an import row into the value that
view.create() expects for this field.
Delegates to :meth:parse_form_data by building a minimal
:class:~starlette.datastructures.FormData from the cell value, so
import parsing stays consistent with form-submission parsing. When
value is a list (e.g. a multi-value column from JSON), each item is
added as a separate form entry under self.id so that
:meth:~starlette.datastructures.FormData.getlist returns the full
sequence. Values are stringified through :func:to_form_entry so
non-string primitives round-trip: a date is already an ISO string, a
bool becomes "true"/"false", and a dict/list becomes
json.dumps(...) rather than Python repr, matching what
JSONField.parse_form_data feeds to json.loads.
Override this method for fields whose import logic cannot be expressed
as a simple :class:FormData round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The request being processed. |
required |
value
|
Any
|
Raw value (string, number, bool, list, …) read from the import file for this field's column. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value to store in the |
Source code in starlette_admin/fields.py
parse_input(request, raw)
async
Single entry point for turning raw input into this field's value.
Routes to parse_import_value
when request.state.action is IMPORT, otherwise to
parse_form_data
(CREATE, EDIT, INLINE_EDIT).
Checks self.parser first, keyed by request.state.action: when the
current action has an entry, its callable replaces the field's
default parsing entirely, and raw is passed to it unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
Any
|
A |
required |
Source code in starlette_admin/fields.py
parse_obj(request, obj)
async
Extracts the value of this field from a model instance.
By default, this function returns the value of the attribute with the name self.name from obj,
or the result of self.getter(request, obj) when getter is set.
This function can also be overridden to provide custom logic for computing the value of a field.
Example
# Suppose we have a `User` model with `id`, `first_name`, and `last_name` fields.
# We define a custom field called `MyCustomField` to compute the full name of the user:
class MyCustomField(StringField):
async def parse_obj(self, request: Request, obj: Any) -> Any:
return f"{obj.first_name} {obj.last_name}" # Returns the full name of the user
# Then, we can define our view as follows
class UserView(ModelView):
fields = ["id", MyCustomField("full_name")]
Source code in starlette_admin/fields.py
serialize_none_value(request)
async
Formats a None value for sending to the frontend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The current request object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The formatted None value. |
Source code in starlette_admin/fields.py
serialize_value(request, value)
async
Formats a value for sending to the frontend based on the current request action.
Important
Make sure this value is JSON Serializable for RequestAction.LIST and RequestAction.RELATION_LOOKUP
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The current request object. |
required |
value
|
Any
|
The value to format. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The formatted value. |
Source code in starlette_admin/fields.py
validate(request, value, form_values)
async
Validates this field's parsed form value, raising ValueError on
the first failure.
An empty value (None, "", or an empty collection) is only checked
against required; the validators chain runs solely on non-empty
values, so validators never have to handle missing input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The request being processed. |
required |
value
|
Any
|
This field's own parsed value. |
required |
form_values
|
dict[str, Any]
|
The full submitted data, keyed by field name, parsed before validation started. |
required |
Source code in starlette_admin/fields.py
Text
starlette_admin.fields.StringField
dataclass
Bases: BaseField
This field is used to represent any kind of short text content.
Source code in starlette_admin/fields.py
starlette_admin.fields.TextAreaField
dataclass
Bases: StringField
This field is used to represent any kind of long text content. For short text contents, use StringField
Source code in starlette_admin/fields.py
starlette_admin.fields.TinyMCEEditorField
dataclass
Bases: TextAreaField
A field that provides a WYSIWYG editor for long text content using the TinyMCE library.
This field can be used as an alternative to the TextAreaField to provide a more sophisticated editor for user input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version_tinymce
|
str
|
TinyMCE version |
'6.4'
|
version_tinymce_jquery
|
str
|
TinyMCE jQuery version |
'2.0'
|
height
|
int
|
Height of the editor |
300
|
menubar
|
bool | str
|
Show/hide the menubar in the editor |
False
|
statusbar
|
bool
|
Show/hide the statusbar in the editor |
False
|
toolbar
|
str
|
Toolbar options to show in the editor |
'undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat'
|
content_style
|
str
|
CSS style to apply to the editor content |
'body { font-family: -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }'
|
extra_options
|
dict[str, Any]
|
Other options to pass to TinyMCE |
dict()
|
Source code in starlette_admin/fields.py
extra_options = dc_field(default_factory=dict)
class-attribute
instance-attribute
For more options, see the TinyMCE | Documentation
starlette_admin.fields.EmailField
dataclass
Bases: StringField
This field is used to represent a text content that stores a single email address.
email is used as the default validator
when validators is empty, to ensure the value is a valid email address.
Pass your own validators to override it.
Source code in starlette_admin/fields.py
starlette_admin.fields.URLField
dataclass
Bases: StringField
This field is used to represent a text content that stores a single URL.
url is used as the default validator
when validators is empty, to ensure the value is a valid absolute URL.
Pass your own validators to override it.
Attributes:
| Name | Type | Description |
|---|---|---|
allowed_schemes |
Collection[str] | None
|
Schemes allowed when rendering the value on the list
and detail pages. Any other scheme (javascript:, data:, vbscript:,
…) is stripped. Defaults to |
Source code in starlette_admin/fields.py
starlette_admin.fields.PhoneField
dataclass
Bases: StringField
A StringField, except renders an <input type="phone">.
Source code in starlette_admin/fields.py
starlette_admin.fields.ColorField
dataclass
Bases: StringField
A StringField, except renders an <input type="color">.
Source code in starlette_admin/fields.py
starlette_admin.fields.PasswordField
dataclass
Bases: StringField
A StringField, except renders an <input type="password">.
Source code in starlette_admin/fields.py
starlette_admin.fields.UUIDField
dataclass
Bases: StringField
This field is used to represent a text content that stores a single UUID.
uuid is used as the default validator
when validators is empty, restricted to version when set, to ensure
the value is a valid UUID. Pass your own validators to override it.
Attributes:
| Name | Type | Description |
|---|---|---|
version |
int | None
|
When set (1, 3, 4, or 5), also requires the UUID to be of that version. |
Source code in starlette_admin/fields.py
starlette_admin.fields.IPAddressField
dataclass
Bases: StringField
This field is used to represent a text content that stores a single IP address.
ip_address is used as the default
validator when validators is empty, restricted to ipv4/ipv6 when set,
to ensure the value is a valid IP address. Pass your own validators to
override it.
Attributes:
| Name | Type | Description |
|---|---|---|
ipv4 |
bool
|
If |
ipv6 |
bool
|
If |
Source code in starlette_admin/fields.py
starlette_admin.fields.SlugField
dataclass
Bases: StringField
A text field that is auto-populated (client-side) from another field as the user types, editable but pre-filled with a URL-safe slug.
The populate_from parameter must be the name of another field on the
same form. A small piece of JavaScript watches that source field and fills
this field whenever it is empty (or still matches the auto-generated value).
Once the user manually edits the slug field the auto-fill stops, so an
intentional override is never clobbered.
Source code in starlette_admin/fields.py
Numbers
starlette_admin.fields.NumberField
dataclass
Bases: StringField
This field is used to represent the value of properties that store numbers of any type (integers or decimals). Should not be used directly. use IntegerField or DecimalField
Source code in starlette_admin/fields.py
starlette_admin.fields.IntegerField
dataclass
Bases: NumberField
This field is used to represent the value of properties that store integer numbers. Erroneous input is ignored and will not be accepted as a value.
Source code in starlette_admin/fields.py
starlette_admin.fields.DecimalField
dataclass
Bases: NumberField
This field is used to represent the value of properties that store decimal numbers. Erroneous input is ignored and will not be accepted as a value.
Source code in starlette_admin/fields.py
starlette_admin.fields.FloatField
dataclass
Bases: StringField
A text field, except all input is coerced to an float. Erroneous input is ignored and will not be accepted as a value.
Source code in starlette_admin/fields.py
Boolean
starlette_admin.fields.BooleanField
dataclass
Bases: BaseField
This field displays the true/false value of a boolean property.
Source code in starlette_admin/fields.py
Dates and times
starlette_admin.fields.DateTimeField
dataclass
Bases: NumberField
This field represents a datetime.datetime object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_format
|
str | None
|
The moment.js format to use for searching. Use |
None
|
output_format
|
str | None
|
The format for displaying the output. |
None
|
Source code in starlette_admin/fields.py
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 | |
starlette_admin.fields.DateField
dataclass
Bases: DateTimeField
This field represents a datetime.date object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_format
|
str
|
The moment.js format to use for searching. Use |
'YYYY-MM-DD'
|
output_format
|
str | None
|
Sets the display output format. |
None
|
Source code in starlette_admin/fields.py
starlette_admin.fields.TimeField
dataclass
Bases: DateTimeField
This field represents a datetime.time object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_format
|
str
|
The format to use for searching. Use |
'HH:mm:ss'
|
output_format
|
str | None
|
Sets the display output format. |
None
|
Source code in starlette_admin/fields.py
starlette_admin.fields.ArrowField
dataclass
Bases: DateTimeField
This field represents a sqlalchemy_utils.types.arrow.ArrowType.
Source code in starlette_admin/fields.py
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 | |
Choices
starlette_admin.fields.EnumField
dataclass
Bases: StringField
Enumeration Field.
It takes a python enum.Enum class or a list of (value, label) pairs.
It can also be a list of only values, in which case the value is used as the label.
Example:
class Status(str, enum.Enum):
NEW = "new"
ONGOING = "ongoing"
DONE = "done"
class MyModel:
status: Optional[Status] = None
class MyModelView(ModelView):
fields = [EnumField("status", enum=Status)]
```python
class MyModel:
language: str
class MyModelView(ModelView):
fields = [
EnumField(
"language",
choices=[("cpp", "C++"), ("py", "Python"), ("text", "Plain Text")],
)
]
```
Source code in starlette_admin/fields.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 | |
get_create_default(request)
async
Coerce the configured default to raw choice value(s).
Source code in starlette_admin/fields.py
starlette_admin.fields.TimeZoneField
dataclass
Bases: EnumField
This field is used to represent the name of a timezone (eg. Africa/Porto-Novo)
Source code in starlette_admin/fields.py
starlette_admin.fields.CountryField
dataclass
Bases: EnumField
This field is used to represent the name that corresponds to the country code stored in your database
Source code in starlette_admin/fields.py
starlette_admin.fields.CurrencyField
dataclass
Bases: EnumField
This field represents a value that stores the 3-letter ISO 4217 currency code.
Source code in starlette_admin/fields.py
starlette_admin.fields.TagsField
dataclass
Bases: BaseField
This field is used to represent the value of properties that store a list of
string values. Render as select2 tags input.
Source code in starlette_admin/fields.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 | |
Structured data
starlette_admin.fields.JSONField
dataclass
Bases: BaseField
This field renders a JSON editor and represents a Python dict object.
Erroneous input is ignored and will not be accepted.
You may optionally use the validation_schema property to provide a dictionary with
a JSONSchema for client-side validation feedback.
The read-only viewer (for list/detail views) can be configured with viewer_collapsed
(renders collapsed on load), viewer_with_quotes (quotes object keys),
viewer_with_links (renders string values that resemble URLs as clickable
links), and viewer_root_collapsable (shows a toggle to collapse/expand the
root value itself).
Source code in starlette_admin/fields.py
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 | |
starlette_admin.fields.CollectionField
dataclass
Bases: BaseField
This field represents a collection of other fields. It can be used to represent an embedded MongoDB document.
Usage
CollectionField("config", fields=[StringField("key"), IntegerField("value", help_text="multiple of 5")]),
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
See BaseField.name. |
required |
fields
|
Sequence[BaseField]
|
The sub-fields that make up this collection. |
required |
required
|
bool
|
If |
False
|
validators
|
list[Validator] | None
|
Validators run against the parsed collection value (a |
None
|
getter
|
Getter | None
|
See BaseField.getter. |
None
|
formatter
|
dict[RequestAction, Formatter] | None
|
See BaseField.formatter. |
None
|
parser
|
dict[RequestAction, Parser] | None
|
See BaseField.parser. Its
callable receives the full |
None
|
Source code in starlette_admin/fields.py
2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 | |
parse_input(request, raw)
async
Overrides BaseField.parse_input
because a collection's sub-fields are keyed by dotted id
(self.id.<subfield>) rather than living under a single self.id
key, so the base implementation's raw.get(self.id) extraction does
not apply. For CREATE, EDIT, and INLINE_EDIT, when self.parser has
an entry for the current action, the full FormData is passed to it
unchanged, mirroring what
[parse_form_data][starlette_admin.fields.CollectionField.parse_form_data]
itself receives.
Source code in starlette_admin/fields.py
validate(request, value, form_values)
async
Extends BaseField.validate
by also running each sub-field's own validate (its required check
and validators) against its corresponding entry in value, after
this field's own validators have passed. Sub-field failures are
collected into a single ValueError carrying a dict keyed by
sub-field name, matching the shape the form templates already know
how to render.
Source code in starlette_admin/fields.py
starlette_admin.fields.ListField
dataclass
Bases: BaseField
Encapsulate an ordered list of multiple instances of the same field type, keeping data as a list.
Usage
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
BaseField
|
The field type repeated for each item in the list. |
required |
required
|
bool
|
If |
False
|
validators
|
list[Validator] | None
|
Validators run against the parsed list value. |
None
|
getter
|
Getter | None
|
See BaseField.getter. |
None
|
formatter
|
dict[RequestAction, Formatter] | None
|
See BaseField.formatter. |
None
|
parser
|
dict[RequestAction, Parser] | None
|
See BaseField.parser. Its
callable receives the full |
None
|
Source code in starlette_admin/fields.py
2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 | |
parse_input(request, raw)
async
Overrides BaseField.parse_input
because a list's items are keyed by index (self.id.0, self.id.1, ...)
rather than living under a single self.id key, so the base
implementation's raw.get(self.id) / raw.getlist(self.id) extraction
does not apply. For CREATE, EDIT, and INLINE_EDIT, when self.parser
has an entry for the current action, the full FormData is passed to
it unchanged, mirroring what [parse_form_data][starlette_admin.fields.ListField.parse_form_data]
itself receives.
Source code in starlette_admin/fields.py
validate(request, value, form_values)
async
Extends BaseField.validate
by also running the inner field's own validate (its required
check and validators) against each item in value, after this
field's own validators have passed. Item failures are collected
into a single ValueError carrying a dict keyed by item index,
matching the shape the form templates already know how to render.
Source code in starlette_admin/fields.py
starlette_admin.fields.ComputedField
dataclass
Bases: StringField
A read-only virtual field whose value is derived from the model object at display time. No database column is required.
Pass a getter for inline use:
Or subclass and override :meth:parse_obj for reusable fields:
class FullNameField(ComputedField):
async def parse_obj(self, request: Request, obj: Any) -> str:
return f"{obj.first_name} {obj.last_name}"
The field is excluded from create forms by default (there is no object yet) and is always read-only. It can still appear on edit forms as a plain-text display so the user sees the current computed value.
Source code in starlette_admin/fields.py
Files
starlette_admin.fields.FileField
dataclass
Bases: BaseField
Renders a file upload field.
When a storage is attached, uploads are saved through it by the admin. The database column only stores the JSON metadata dictionary of a FileInfo.
Without a storage, this field retains its legacy behavior: it represents a
value that stores a Starlette UploadFile object. parse_form_data
returns the raw (upload(s), should_be_deleted) tuple for the backend to
process itself. For displaying values, this field expects three
properties: filename, content-type, and url.
Use multiple=True for multiple file uploads.
When a user requests deletion on the editing page, the second part of the returned tuple is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accept
|
str | None
|
Comma-separated accepted file specifiers (e.g., |
None
|
multiple
|
bool
|
Allows uploading (and storing) several files. |
False
|
storage
|
BaseStorage | None
|
The storage backend to which uploads are delegated. |
None
|
upload_folder
|
str
|
The storage-relative folder where uploads for this field are saved. |
''
|
max_size
|
int | None
|
The maximum accepted upload size, in bytes (default: 50 MB).
Set to |
DEFAULT_MAX_UPLOAD_SIZE
|
validators
|
list[Validator]
|
Additional validators executed after the built-in
|
list()
|
File fields are always excluded from import (exclude_from_import defaults
to True): there is no way to reference an uploaded file's bytes from a
CSV/Excel/JSON row, so the column is left for the backend to populate
through the normal create/edit forms instead.
Source code in starlette_admin/fields.py
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 | |
validate(request, value, form_values)
async
Validates each uploaded file in the parsed (upload(s), should_be_deleted)
tuple against accept, max_size, and the custom validators, raising
ValueError upon the first failure encountered.
The base required check does not apply: an empty submission on an
edit form means "keep the current file", which this field cannot
distinguish from a missing value.
Source code in starlette_admin/fields.py
starlette_admin.fields.ImageField
dataclass
Bases: FileField
A FileField with accept="image/*". When a storage is attached and Pillow is
installed, the image dimensions (width/height) are automatically added to the stored
metadata.
valid_image is automatically prepended
to validators to ensure every upload is a valid image before storage. Override
__post_init__ (or validate) to opt out of this behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thumbnail_size
|
tuple[int, int] | None
|
When set (and a storage is attached), a thumbnail bounded
to |
None
|
The detail page renders every ImageField image inside an
fslightbox anchor, grouped into one gallery per
field, so visitors can click through to a full-size, navigable view.
Source code in starlette_admin/fields.py
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 | |
Relations
starlette_admin.fields.RelationField
dataclass
Bases: BaseField
A field representing a relation between two data models.
This field should not be used directly. Instead, use either the HasOne or HasMany fields to specify a relation between your models.
Important
It is important to add both models to your admin interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | None
|
The key of the foreign ModelView. |
None
|
Example
class Author:
id: Optional[int]
name: str
books: List["Book"]
class Book:
id: Optional[int]
title: str
author: Optional["Author"]
class AuthorView(ModelView):
fields = [
IntegerField("id"),
StringField("name"),
HasMany("books", key="book"),
]
class BookView(ModelView):
fields = [
IntegerField("id"),
StringField("title"),
HasOne("author", key="author"),
]
...
admin.add_view(AuthorView(Author, key="author"))
admin.add_view(BookView(Book, key="book"))
...
Source code in starlette_admin/fields.py
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 | |
starlette_admin.fields.HasOne
dataclass
starlette_admin.fields.HasMany
dataclass
Bases: RelationField
A field representing a "has-many" relationship between two models.