Contrib: MongoEngine
Full attribute and method reference for the MongoEngine backend
(starlette_admin.contrib.mongoengine), generated from docstrings. For a task-oriented
walkthrough, see MongoEngine.
starlette_admin.contrib.mongoengine.admin.Admin
Bases: BaseAdmin
MongoEngine-flavored BaseAdmin that also mounts the GridFS file-serving route.
Source code in starlette_admin/contrib/mongoengine/admin.py
starlette_admin.contrib.mongoengine.view.ModelView
Bases: BaseModelView
BaseModelView backed by a mongoengine.Document.
Wraps a document class and implements CRUD, search, filtering, and sorting
against it, converting its declared fields to admin fields via converter.
Source code in starlette_admin/contrib/mongoengine/view.py
38 39 40 41 42 43 44 45 46 47 48 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 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 | |
__init__(document, icon=None, display_name=None, menu_label=None, key=None, converter=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
type[Document]
|
The mongoengine document class this view manages. |
required |
icon
|
str | None
|
CSS class for the icon shown in the admin menu. |
None
|
display_name
|
str | None
|
Display name for the view. Defaults to the prettified document class name. |
None
|
menu_label
|
str | None
|
Display label for the view. Defaults to the pluralized, prettified document class name. |
None
|
key
|
str | None
|
URL-safe identifier for the view. Defaults to the slugified document class name. |
None
|
converter
|
BaseMongoEngineModelConverter | None
|
Converter used to turn the document's fields into admin
fields. Defaults to |
None
|
Source code in starlette_admin/contrib/mongoengine/view.py
build_full_text_search_query(request, term)
async
Build a QNode matching term case-insensitively against every
searchable text-like field (string, text area, email, URL, phone, color),
excluding the primary key. Fragments are combined with | (OR).
Source code in starlette_admin/contrib/mongoengine/view.py
count(request, q=None, filters=None)
async
Return the number of documents matching the search term and filters.
Source code in starlette_admin/contrib/mongoengine/view.py
create(request, data)
async
Create and save a new document from converted form data.
Emits BeforeCreateContext/AfterCreateContext events around the save.
Exceptions are routed through handle_exception.
Source code in starlette_admin/contrib/mongoengine/view.py
delete(request, pks)
async
Delete the documents whose primary key is in pks.
Emits BeforeDeleteContext/AfterDeleteContext events for each
affected document around the bulk delete.
Returns:
| Type | Description |
|---|---|
int | None
|
The number of documents deleted. |
Source code in starlette_admin/contrib/mongoengine/view.py
edit(request, pk, data)
async
Apply converted form data to the document identified by pk and save it.
Emits BeforeEditContext/AfterEditContext events around the save.
Exceptions are routed through handle_exception.
Source code in starlette_admin/contrib/mongoengine/view.py
find_all(request, skip=0, limit=100, q=None, sorts=None, filters=None)
async
Return a page of documents matching the search term and filters, sorted
according to sorts.
A non-positive limit returns every matching document from skip onward.
Source code in starlette_admin/contrib/mongoengine/view.py
find_by_pk(request, pk)
async
Return the document with primary key pk, or None if it does not
exist or pk is not a valid ObjectId.
Source code in starlette_admin/contrib/mongoengine/view.py
find_by_pks(request, pks)
async
Return the documents whose primary key is in pks.
Source code in starlette_admin/contrib/mongoengine/view.py
get_filter_registry()
Return the registry used to resolve available filters for this view's fields.
handle_exception(request, exc)
async
Translate a mongoengine ValidationError into a FormValidationError
so field-level errors surface on the form. Any other exception is logged
and re-raised unchanged.
Source code in starlette_admin/contrib/mongoengine/view.py
starlette_admin.contrib.mongoengine.view.InlineModelView
Bases: InlineModelView, ModelView
Inline editing of MongoEngine-backed related documents inside a parent form.
Declare document as a class attribute. The parent reference field is
auto-detected by scanning the child document's fields for a
ReferenceField whose document_type matches the parent document.
Example::
class CommentInline(InlineModelView):
document = Comment
fields = ["id", "author", "body"]
extra = 2
class ArticleView(ModelView):
document = Article
inlines = [CommentInline]
Source code in starlette_admin/contrib/mongoengine/view.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
find_by_parent(request, parent)
async
Return the child documents whose fk_attr equals parent's primary key.
Source code in starlette_admin/contrib/mongoengine/view.py
Fields
starlette_admin.contrib.mongoengine.fields.ObjectIdField
dataclass
Bases: StringField
A string field whose underlying value is a MongoDB ObjectId.
Registered separately from StringField so the filter registry can bind ObjectId-aware filters (eq/neq/in/not_in only) instead of string filters.
Source code in starlette_admin/contrib/mongoengine/fields.py
starlette_admin.contrib.mongoengine.fields.FileField
dataclass
Bases: FileField
FileField backed by a MongoEngine GridFSProxy.
Serializes the stored file to a {filename, content_type, url} dict
instead of the base class's default handling.
Source code in starlette_admin/contrib/mongoengine/fields.py
starlette_admin.contrib.mongoengine.fields.ImageField
dataclass
Bases: ImageField
ImageField backed by a MongoEngine GridFSProxy.
Serializes the same way as FileField,
and serves the proxy's thumbnail_id (when present) in the list view.
Source code in starlette_admin/contrib/mongoengine/fields.py
Converters
starlette_admin.contrib.mongoengine.converters.BaseMongoEngineModelConverter
Bases: BaseModelConverter
Base class for converting mongoengine document fields to admin fields.
Subclasses register one converter method per mongoengine field type using the [converts][starlette_admin.converters.converts] decorator.
Source code in starlette_admin/contrib/mongoengine/converters.py
convert(*args, **kwargs)
Convert a single mongoengine field, passed as the field keyword argument,
to its admin field equivalent.
Source code in starlette_admin/contrib/mongoengine/converters.py
convert_fields_list(*, fields, model, **kwargs)
Convert a mixed list of field specs into a list of admin fields.
Each entry in fields may already be a sa.BaseField instance (passed
through unchanged), a mongoengine field instance, or a string naming an
attribute on model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
Sequence[Any]
|
The field specs to convert. |
required |
model
|
type[Document]
|
The document class |
required |
Returns:
| Type | Description |
|---|---|
Sequence[BaseField]
|
The converted admin fields, in the same order as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a string entry does not name an attribute on |
Source code in starlette_admin/contrib/mongoengine/converters.py
get_converter(field)
Look up the converter function registered for field's type.
Tries an exact class match first, then falls back to the first
registered class that field is an instance of, so a converter
registered for a base mongoengine field type also matches its subclasses.
Raises:
| Type | Description |
|---|---|
NotSupportedField
|
If no registered converter matches |
Source code in starlette_admin/contrib/mongoengine/converters.py
starlette_admin.contrib.mongoengine.converters.ModelConverter
Bases: BaseMongoEngineModelConverter
Default converter mapping mongoengine field types to starlette_admin fields.
Source code in starlette_admin/contrib/mongoengine/converters.py
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 | |
conv_embedded_document_field(*args, **kwargs)
Convert an EmbeddedDocumentField to a CollectionField.
Recursively converts each field of the embedded document type, in the order declared on that type.
Source code in starlette_admin/contrib/mongoengine/converters.py
conv_list_field(*args, **kwargs)
Convert a ListField/SortedListField based on its inner field type.
A list of references becomes a HasMany relation. A list of dicts or
maps collapses to a single JSONField, since JSON already represents
nested lists natively. A list of enum values becomes a multi-select
dropdown over the enum's choices. Everything else is wrapped in a
generic ListField around the converted inner field.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Source code in starlette_admin/contrib/mongoengine/converters.py
conv_reference_field(*args, **kwargs)
Convert a ReferenceField to a HasOne relation.
document_type_obj is a class for direct references and a string for
lazy references (declared before the target class exists); both are
normalized to the same key slug.
Source code in starlette_admin/contrib/mongoengine/converters.py
Exceptions
starlette_admin.contrib.mongoengine.exceptions.NotSupportedField
Note
Concrete filter classes (EqualFilter, ArrayInFilter, ObjectIdEqualFilter, and so on) are
not enumerated here. They mirror the backend-agnostic filters documented in
Filters; MongoEngine-specific behavior is covered in
MongoEngine.