Contrib: Beanie
Full attribute and method reference for the Beanie backend (starlette_admin.contrib.beanie),
generated from docstrings. For a task-oriented walkthrough, see
Beanie.
starlette_admin.contrib.beanie.admin.Admin
starlette_admin.contrib.beanie.view.ModelView
Bases: BaseModelView, Generic[T]
A view for managing Beanie documents.
Source code in starlette_admin/contrib/beanie/view.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 | |
full_text_override_order_by = False
class-attribute
instance-attribute
When True, list-page results matched through a MongoDB $text index
are sorted by relevance score instead of the view's configured sort. Has
no effect for the regex-based fallback used when the collection has no
text index.
build_full_text_search_query(request, term)
async
Build the Beanie find operator used for the list page's search box.
Uses the collection's MongoDB text index when one exists. Otherwise,
falls back to a case-insensitive regex OR across the searchable
string-like fields (StringField, TextAreaField, EmailField,
URLField, PhoneField, ColorField), excluding id.
Returns:
| Type | Description |
|---|---|
BaseFindOperator
|
A tuple of the find operator to pass to |
bool
|
whether it's a MongoDB |
tuple[BaseFindOperator, bool]
|
query ( |
Source code in starlette_admin/contrib/beanie/view.py
check_full_text_index()
async
Detect whether the document's collection has a MongoDB text index.
Sets has_full_text_index accordingly. build_full_text_search_query
calls this once and reuses the cached result for later searches.
Source code in starlette_admin/contrib/beanie/view.py
get_filter_registry()
Return the FilterRegistry
of concrete Beanie filter implementations
(starlette_admin.contrib.beanie.filters) used to determine which
filters are available for each field on this view's list page.
Source code in starlette_admin/contrib/beanie/view.py
starlette_admin.contrib.beanie.view.InlineModelView
Bases: InlineModelView, ModelView
Inline editing of Beanie-backed related documents inside a parent form.
Declare document as a class attribute. The FK field is either set
explicitly via fk_attr or auto-detected by scanning the child
document's model fields for a Link[ParentDoc] field.
Both plain PydanticObjectId FK fields and Link[Parent] fields are
supported. For a plain ObjectId FK, the value returned by
build_fk_value is parent.id; for a Link FK, it is the full parent
document so Beanie can build the DBRef on save.
Example
Source code in starlette_admin/contrib/beanie/view.py
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 | |
build_fk_value(request, parent)
async
Return the value to store in fk_attr for a newly created inline row.
Returns the full parent document when fk_attr is a Beanie Link
field, since Beanie needs the document instance to build the DBRef.
Otherwise returns parent.id for a plain PydanticObjectId FK field.
Source code in starlette_admin/contrib/beanie/view.py
find_by_parent(request, parent)
async
Return all inline rows whose FK field references parent.
A Link FK is stored as a DBRef, so it's matched through its
embedded $id key rather than the field itself.
Source code in starlette_admin/contrib/beanie/view.py
Fields
starlette_admin.contrib.beanie.fields.BeanieObjectIdField
dataclass
Bases: StringField
StringField subclass used for Beanie's PydanticObjectId fields.
Kept as a distinct type so the filter registry can register ObjectId-aware filters (eq/neq/in/not-in with ObjectId parsing) without colliding with the string filters registered for plain StringField.
Source code in starlette_admin/contrib/beanie/fields.py
Converters
starlette_admin.contrib.beanie.converters.BeanieModelConverter
Bases: StandardModelConverter
Converts Beanie Document fields to starlette_admin BaseField instances.
Extends StandardModelConverter with converters for Beanie- and
pydantic-specific types: PydanticObjectId, Link/BackLink, SecretStr,
EmailStr, AnyUrl, the pydantic date/datetime constrained types, and
nested BaseModels.
Source code in starlette_admin/contrib/beanie/converters.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 | |
conv_base_model(name, required, *args, **kwargs)
Convert a nested pydantic BaseModel annotation to a CollectionField.
Recursively converts each of the model's own fields and nests the
results under a single CollectionField named name.
Source code in starlette_admin/contrib/beanie/converters.py
conv_link(*args, **kwargs)
Convert a Beanie Link[T] or list[Link[T]] annotation to a relation field.
A single Link[T] becomes a HasOne field; list[Link[T]] becomes a
HasMany field. Both derive their key from T's class name.
Source code in starlette_admin/contrib/beanie/converters.py
convert_fields_list(*, fields, model, **kwargs)
Convert a mixed list of field names, ExpressionFields, and
BaseField instances into a list of BaseField instances.
BaseField instances pass through unchanged. ExpressionFields
(e.g., Model.id) are resolved to their attribute name first. Every
other entry is validated against model with isvalid_field and
routed to conv_link for Link/list[Link[T]] annotations, or to
the standard convert dispatch otherwise.
Source code in starlette_admin/contrib/beanie/converters.py
get_type_beanie(model_fields, value)
Return the annotated type of value in model_fields.
Unwraps a Union/Optional annotation by repeatedly taking its first
type argument, so Optional[X] resolves to X.