From ed2058c3daab5d43e088aca7536eb286c9d0cd1e Mon Sep 17 00:00:00 2001 From: <> Date: Sat, 26 Oct 2024 01:24:37 +0000 Subject: [PATCH] Deployed a5717c0 with MkDocs version: 1.6.1 --- .nojekyll | 0 404.html | 1338 +++ advanced/base-model-view/index.html | 1761 ++++ advanced/custom-field/index.html | 1684 ++++ alternatives/index.html | 1432 ++++ api/actions/index.html | 2620 ++++++ api/auth/index.html | 3456 ++++++++ api/base-admin/index.html | 3024 +++++++ api/contrib/sqlalchemy/modelview/index.html | 3284 ++++++++ api/fields/index.html | 7194 ++++++++++++++++ api/views/index.html | 7317 ++++++++++++++++ assets/_mkdocstrings.css | 143 + assets/favicon.ico | Bin 0 -> 5238 bytes assets/images/favicon.png | Bin 0 -> 1870 bytes assets/images/tutorials/basic/create.png | Bin 0 -> 23977 bytes assets/images/tutorials/basic/delete.png | Bin 0 -> 107938 bytes assets/images/tutorials/basic/edit.png | Bin 0 -> 28287 bytes assets/images/tutorials/basic/export.png | Bin 0 -> 30728 bytes .../tutorials/basic/fulltext_search.png | Bin 0 -> 34572 bytes assets/images/tutorials/basic/home_page.png | Bin 0 -> 8176 bytes assets/images/tutorials/basic/list_full.png | Bin 0 -> 49448 bytes assets/images/tutorials/basic/pagination.png | Bin 0 -> 25336 bytes .../images/tutorials/basic/search_builder.png | Bin 0 -> 38523 bytes .../tutorials/basic/show_hide_columns.png | Bin 0 -> 39156 bytes assets/javascripts/bundle.83f73b43.min.js | 16 + assets/javascripts/bundle.83f73b43.min.js.map | 7 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.el.min.js | 1 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.he.min.js | 1 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.kn.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + assets/javascripts/lunr/min/lunr.sa.min.js | 1 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.te.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++ .../workers/search.6ce7567c.min.js | 42 + .../workers/search.6ce7567c.min.js.map | 7 + assets/stylesheets/main.0253249f.min.css | 1 + assets/stylesheets/main.0253249f.min.css.map | 1 + assets/stylesheets/palette.06af60db.min.css | 1 + .../stylesheets/palette.06af60db.min.css.map | 1 + changelog/index.html | 3785 +++++++++ deployment/index.html | 1444 ++++ es/advanced/base-model-view/index.html | 1763 ++++ es/advanced/custom-field/index.html | 1686 ++++ es/alternatives/index.html | 1434 ++++ es/api/actions/index.html | 2622 ++++++ es/api/auth/index.html | 3458 ++++++++ es/api/base-admin/index.html | 3026 +++++++ .../contrib/sqlalchemy/modelview/index.html | 3286 ++++++++ es/api/fields/index.html | 7196 ++++++++++++++++ es/api/views/index.html | 7319 +++++++++++++++++ es/changelog/index.html | 3787 +++++++++ es/deployment/index.html | 1446 ++++ es/index.html | 1686 ++++ es/tutorials/basic/index.html | 2288 ++++++ es/tutorials/index.html | 1504 ++++ es/user-guide/actions/index.html | 1807 ++++ es/user-guide/authentication/index.html | 1860 +++++ es/user-guide/configurations/admin/index.html | 1522 ++++ .../configurations/modelview/index.html | 1925 +++++ es/user-guide/files/index.html | 1554 ++++ es/user-guide/getting-started/index.html | 1847 +++++ es/user-guide/multiple-admin/index.html | 1459 ++++ es/user-guide/validations/index.html | 1747 ++++ images/preview.jpg | Bin 0 -> 249852 bytes .../modelview/object_text_representation.png | Bin 0 -> 51659 bytes .../modelview/select2_customization.png | Bin 0 -> 85041 bytes images/validations/mongoengine.png | Bin 0 -> 95008 bytes images/validations/odmantic.png | Bin 0 -> 101537 bytes images/validations/sqla.png | Bin 0 -> 121123 bytes images/validations/sqlmodel.png | Bin 0 -> 91710 bytes index.html | 1748 ++++ objects.inv | Bin 0 -> 2389 bytes search/search_index.json | 1 + sitemap.xml | 311 + sitemap.xml.gz | Bin 0 -> 922 bytes stylesheets/extra.css | 4 + tutorials/basic/index.html | 2286 +++++ tutorials/index.html | 1502 ++++ user-guide/actions/index.html | 1805 ++++ user-guide/authentication/index.html | 1858 +++++ user-guide/configurations/admin/index.html | 1520 ++++ .../configurations/modelview/index.html | 1923 +++++ user-guide/files/index.html | 1552 ++++ user-guide/getting-started/index.html | 1845 +++++ user-guide/multiple-admin/index.html | 1457 ++++ user-guide/validations/index.html | 1745 ++++ 113 files changed, 121538 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 advanced/base-model-view/index.html create mode 100644 advanced/custom-field/index.html create mode 100644 alternatives/index.html create mode 100644 api/actions/index.html create mode 100644 api/auth/index.html create mode 100644 api/base-admin/index.html create mode 100644 api/contrib/sqlalchemy/modelview/index.html create mode 100644 api/fields/index.html create mode 100644 api/views/index.html create mode 100644 assets/_mkdocstrings.css create mode 100644 assets/favicon.ico create mode 100644 assets/images/favicon.png create mode 100644 assets/images/tutorials/basic/create.png create mode 100644 assets/images/tutorials/basic/delete.png create mode 100644 assets/images/tutorials/basic/edit.png create mode 100644 assets/images/tutorials/basic/export.png create mode 100644 assets/images/tutorials/basic/fulltext_search.png create mode 100644 assets/images/tutorials/basic/home_page.png create mode 100644 assets/images/tutorials/basic/list_full.png create mode 100644 assets/images/tutorials/basic/pagination.png create mode 100644 assets/images/tutorials/basic/search_builder.png create mode 100644 assets/images/tutorials/basic/show_hide_columns.png create mode 100644 assets/javascripts/bundle.83f73b43.min.js create mode 100644 assets/javascripts/bundle.83f73b43.min.js.map create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.el.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.he.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.kn.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sa.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.te.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/workers/search.6ce7567c.min.js create mode 100644 assets/javascripts/workers/search.6ce7567c.min.js.map create mode 100644 assets/stylesheets/main.0253249f.min.css create mode 100644 assets/stylesheets/main.0253249f.min.css.map create mode 100644 assets/stylesheets/palette.06af60db.min.css create mode 100644 assets/stylesheets/palette.06af60db.min.css.map create mode 100644 changelog/index.html create mode 100644 deployment/index.html create mode 100644 es/advanced/base-model-view/index.html create mode 100644 es/advanced/custom-field/index.html create mode 100644 es/alternatives/index.html create mode 100644 es/api/actions/index.html create mode 100644 es/api/auth/index.html create mode 100644 es/api/base-admin/index.html create mode 100644 es/api/contrib/sqlalchemy/modelview/index.html create mode 100644 es/api/fields/index.html create mode 100644 es/api/views/index.html create mode 100644 es/changelog/index.html create mode 100644 es/deployment/index.html create mode 100644 es/index.html create mode 100644 es/tutorials/basic/index.html create mode 100644 es/tutorials/index.html create mode 100644 es/user-guide/actions/index.html create mode 100644 es/user-guide/authentication/index.html create mode 100644 es/user-guide/configurations/admin/index.html create mode 100644 es/user-guide/configurations/modelview/index.html create mode 100644 es/user-guide/files/index.html create mode 100644 es/user-guide/getting-started/index.html create mode 100644 es/user-guide/multiple-admin/index.html create mode 100644 es/user-guide/validations/index.html create mode 100644 images/preview.jpg create mode 100644 images/tutorial/configurations/modelview/object_text_representation.png create mode 100644 images/tutorial/configurations/modelview/select2_customization.png create mode 100644 images/validations/mongoengine.png create mode 100644 images/validations/odmantic.png create mode 100644 images/validations/sqla.png create mode 100644 images/validations/sqlmodel.png create mode 100644 index.html create mode 100644 objects.inv create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz create mode 100644 stylesheets/extra.css create mode 100644 tutorials/basic/index.html create mode 100644 tutorials/index.html create mode 100644 user-guide/actions/index.html create mode 100644 user-guide/authentication/index.html create mode 100644 user-guide/configurations/admin/index.html create mode 100644 user-guide/configurations/modelview/index.html create mode 100644 user-guide/files/index.html create mode 100644 user-guide/getting-started/index.html create mode 100644 user-guide/multiple-admin/index.html create mode 100644 user-guide/validations/index.html diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..32898f57 --- /dev/null +++ b/404.html @@ -0,0 +1,1338 @@ + + + +
+ + + + + + + + + + + + + + + + +Starlette-Admin makes a few assumptions about the database models that it works with. If you want to implement your +own database backend, and still have Starlette-Admin’s model views work as expected, then you should take note of the +following:
+If that is the case, then you can implement your own database backend by extending the +BaseModelView class, and implementing the set of methods listed below.
+Let's say you've defined your models like this:
+from dataclasses import dataclass
+from typing import List
+
+
+@dataclass
+class Post:
+ id: int
+ title: str
+ content: str
+ tags: List[str]
+
First you need to define a new class, which derives from BaseModelView.
+ +Set the identity
, name
and label
for the new class
from starlette_admin import BaseModelView
+
+
+class PostView(BaseModelView):
+ identity = "post"
+ name = "Post"
+ label = "Blog Posts"
+ icon = "fa fa-blog"
+
Important
+identity
is used to identify the model associated to this view and should be unique.
Set the pk_attr
value which is primary key attribute name
Internally, Starlette-Admin uses custom fields all inherit from BaseField to +represent each attribute. So, you need to choose the right field for each attribute or create a new field if needed. +See API Reference for full list of default fields.
+from starlette_admin import BaseModelView
+from starlette_admin import IntegerField, StringField, TagsField, TextAreaField
+
+class PostView(BaseModelView):
+ fields = [
+ IntegerField("id"),
+ StringField("title"),
+ TextAreaField("content"),
+ TagsField("tags"),
+ ]
+
Finally, you need to implement these CRUD methods:
+from dataclasses import dataclass
+from typing import Any, Dict, Iterable, List, Optional, Union
+
+from starlette.requests import Request
+from starlette_admin import IntegerField, StringField, TagsField, TextAreaField
+from starlette_admin.exceptions import FormValidationError
+from starlette_admin.views import BaseModelView
+
+
+@dataclass
+class Post:
+ id: int
+ title: str
+ content: str
+ tags: List[str]
+
+ def is_valid_for_term(self, term):
+ return (
+ str(term).lower() in self.title.lower()
+ or str(term).lower() in self.content.lower()
+ or any([str(term).lower() in tag.lower() for tag in self.tags])
+ )
+
+ def update(self, data: Dict):
+ for key, value in data.items():
+ if hasattr(self, key):
+ setattr(self, key, value)
+
+
+db: Dict[int, Post] = dict()
+next_id = 1
+
+
+def filter_values(values: Iterable[Post], term):
+ filtered_values = []
+ for value in values:
+ if value.is_valid_for_term(term):
+ filtered_values.append(value)
+ return filtered_values
+
+
+class PostView(BaseModelView):
+ identity = "post"
+ name = "Post"
+ label = "Blog Posts"
+ icon = "fa fa-blog"
+ pk_attr = "id"
+ fields = [
+ IntegerField("id"),
+ StringField("title"),
+ TextAreaField("content"),
+ TagsField("tags"),
+ ]
+ sortable_fields = ("id", "title", "content")
+ search_builder = False
+
+ async def count(
+ self,
+ request: Request,
+ where: Union[Dict[str, Any], str, None] = None,
+ ) -> int:
+ values = list(db.values())
+ if where is not None:
+ values = filter_values(values, where)
+ return len(values)
+
+ async def find_all(
+ self,
+ request: Request,
+ skip: int = 0,
+ limit: int = 100,
+ where: Union[Dict[str, Any], str, None] = None,
+ order_by: Optional[List[str]] = None,
+ ) -> List[Any]:
+ values = list(db.values())
+ if order_by is not None:
+ assert len(order_by) < 2, "Not supported"
+ if len(order_by) == 1:
+ key, dir = order_by[0].split(maxsplit=1)
+ values.sort(key=lambda v: getattr(v, key), reverse=(dir == "desc"))
+
+ if where is not None and isinstance(where, (str, int)):
+ values = filter_values(values, where)
+ if limit > 0:
+ return values[skip : skip + limit]
+ return values[skip:]
+
+ async def find_by_pk(self, request: Request, pk):
+ return db.get(int(pk), None)
+
+ async def find_by_pks(self, request: Request, pks):
+ return [db.get(int(pk)) for pk in pks]
+
+ async def validate_data(self, data: Dict):
+ errors = {}
+ if data["title"] is None or len(data["title"]) < 3:
+ errors["title"] = "Ensure title has at least 03 characters"
+ if data["tags"] is None or len(data["tags"]) < 1:
+ errors["tags"] = "You need at least one tag"
+ if len(errors) > 0:
+ raise FormValidationError(errors)
+
+ async def create(self, request: Request, data: Dict):
+ await self.validate_data(data)
+ global next_id
+ obj = Post(id=next_id, **data)
+ db[next_id] = obj
+ next_id += 1
+ return obj
+
+ async def edit(self, request: Request, pk, data: Dict):
+ await self.validate_data(data)
+ db[int(pk)].update(data)
+ return db[int(pk)]
+
+ async def delete(self, request: Request, pks: List[Any]) -> Optional[int]:
+ cnt = 0
+ for pk in pks:
+ value = await self.find_by_pk(request, pk)
+ if value is not None:
+ del db[int(pk)]
+ cnt += 1
+ return cnt
+
Starlette-Admin has a lot of built-in fields available. But you can override or create your own field +according to your need.
+Important
+Before creating a new field, try first to extend the existing ones. They are flexible enough to fit most use cases.
+The first step is to define a new class, which derives from BaseField or any others fields to customize it
+from starlette_admin import BaseField
+from dataclasses import dataclass
+
+@dataclass
+class CustomField(BaseField):
+ pass
+
Starlette-Admin use Datatables to render list. By default all fields will be render as text field. +To customize this behavior you need to write a javascript function to +render your column inside datatable instance. For more information on how to write your function +read Datatables documentation.
+Example
+This is simple example with SQLAlchemy backend
+ + +Note
+fieldOptions
is your field as javascript object. Your field attributes is serialized into
+javascript object by using dataclass asdict
function.
render_function_key
valuefrom starlette_admin import BaseField
+from dataclasses import dataclass
+
+@dataclass
+class CustomField(BaseField):
+ render_function_key: str = "mycustomkey"
+
For form rendering, you should create a new html file under the directory forms
in your templates dir.
These jinja2 variables are available:
+field
: Your field instanceerror
: Error message coming from FormValidationError
data
: current value. Will be available if it is edit or when validation error occuraction
: EDIT
or CREATE
Example
+ +from starlette_admin import BaseField
+from dataclasses import dataclass
+
+@dataclass
+class CustomField(BaseField):
+ render_function_key: str = "mycustomkey"
+ form_template: str = "forms/custom.html"
+
To render your field on detail page, you should create a new html file under the directory displays
in your template dir.
These jinja2 variables are available:
+field
: Your field instancedata
: value to displayfrom starlette_admin import BaseField
+from dataclasses import dataclass
+
+@dataclass
+class CustomField(BaseField):
+ render_function_key: str = "mycustomkey"
+ form_template: str = "forms/custom.html"
+ display_template: str = "displays/custom.html"
+
For data processing you will need to override two functions:
+process_form_data
: Will be call when converting field value into python dict objectserialize_field_value
: Will be call when serializing value to send through the API. This is the same data
+you will get in your render functionfrom dataclasses import dataclass
+from typing import Any, Dict
+
+from requests import Request
+from starlette.datastructures import FormData
+from starlette_admin import BaseField
+
+
+@dataclass
+class CustomField(BaseField):
+ render_function_key: str = "mycustomkey"
+ form_template: str = "forms/custom.html"
+ display_template: str = "displays/custom.html"
+
+ async def parse_form_data(self, request: Request, form_data: FormData) -> Any:
+ return form_data.get(self.name)
+
+ async def serialize_value(self, request: Request, value: Any, action: RequestAction) -> Any:
+ return value
+
+ def dict(self) -> Dict[str, Any]:
+ return super().dict()
+
Important
+Override dict
function to get control of the options which is available in javascript.
starlette_admin.actions
+
+
+action(name, text, confirmation=None, submit_btn_class='btn-primary', submit_btn_text=_('Yes, Proceed'), icon_class=None, form=None, custom_response=False)
+
+Decorator to add custom batch actions to your ModelView
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ name
+ |
+
+ str
+ |
+
+
+
+ unique action name for your ModelView + |
+ + required + | +
+ text
+ |
+
+ str
+ |
+
+
+
+ Action text + |
+ + required + | +
+ confirmation
+ |
+
+ Optional[str]
+ |
+
+
+
+ Confirmation text. If not provided, action will be executed + unconditionally. + |
+
+ None
+ |
+
+ submit_btn_text
+ |
+
+ Optional[str]
+ |
+
+
+
+ Submit button text + |
+
+ lazy_gettext('Yes, Proceed')
+ |
+
+ submit_btn_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Submit button variant (ex. |
+
+ 'btn-primary'
+ |
+
+ icon_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Icon class (ex. |
+
+ None
+ |
+
+ form
+ |
+
+ Optional[str]
+ |
+
+
+
+ Custom form to collect data from user + |
+
+ None
+ |
+
+ custom_response
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Set to True when you want to return a custom Starlette response +from your action instead of a string. + |
+
+ False
+ |
+
Usage
+class ArticleView(ModelView):
+ actions = ['make_published', 'redirect']
+
+ @action(
+ name="make_published",
+ text="Mark selected articles as published",
+ confirmation="Are you sure you want to mark selected articles as published ?",
+ submit_btn_text="Yes, proceed",
+ submit_btn_class="btn-success",
+ form='''
+ <form>
+ <div class="mt-3">
+ <input type="text" class="form-control" name="example-text-input" placeholder="Enter value">
+ </div>
+ </form>
+ '''
+ )
+ async def make_published_action(self, request: Request, pks: List[Any]) -> str:
+ # Write your logic here
+
+ data: FormData = await request.form()
+ user_input = data.get("example-text-input")
+
+ if ... :
+ # Display meaningfully error
+ raise ActionFailed("Sorry, We can't proceed this action now.")
+ # Display successfully message
+ return "{} articles were successfully marked as published".format(len(pks))
+
+ # For custom response
+ @action(
+ name="redirect",
+ text="Redirect",
+ custom_response=True,
+ confirmation="Fill the form",
+ form='''
+ <form>
+ <div class="mt-3">
+ <input type="text" class="form-control" name="value" placeholder="Enter value">
+ </div>
+ </form>
+ '''
+ )
+ async def redirect_action(self, request: Request, pks: List[Any]) -> Response:
+ data = await request.form()
+ return RedirectResponse(f"https://example.com/?value={data['value']}")
+
starlette_admin/actions.py
6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +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 |
|
row_action(name, text, confirmation=None, action_btn_class=None, submit_btn_class='btn-primary', submit_btn_text=_('Yes, Proceed'), icon_class=None, form=None, custom_response=False, exclude_from_list=False, exclude_from_detail=False)
+
+Decorator to add custom row actions to your ModelView
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ name
+ |
+
+ str
+ |
+
+
+
+ Unique row action name for the ModelView. + |
+ + required + | +
+ text
+ |
+
+ str
+ |
+
+
+
+ Action text displayed to users. + |
+ + required + | +
+ confirmation
+ |
+
+ Optional[str]
+ |
+
+
+
+ Confirmation text; if provided, the action will require confirmation. + |
+
+ None
+ |
+
+ action_btn_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Action button variant for detail page (ex. |
+
+ None
+ |
+
+ submit_btn_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Submit button variant (ex. |
+
+ 'btn-primary'
+ |
+
+ submit_btn_text
+ |
+
+ Optional[str]
+ |
+
+
+
+ Text for the submit button. + |
+
+ lazy_gettext('Yes, Proceed')
+ |
+
+ icon_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Icon class (ex. |
+
+ None
+ |
+
+ form
+ |
+
+ Optional[str]
+ |
+
+
+
+ Custom HTML to collect data from the user. + |
+
+ None
+ |
+
+ custom_response
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Set to True when you want to return a custom Starlette response +from your action instead of a string. + |
+
+ False
+ |
+
+ exclude_from_list
+ |
+
+ bool
+ |
+
+
+
+ Set to True to exclude the action from the list view. + |
+
+ False
+ |
+
+ exclude_from_detail
+ |
+
+ bool
+ |
+
+
+
+ Set to True to exclude the action from the detail view. + |
+
+ False
+ |
+
Usage
+@row_action(
+ name="make_published",
+ text="Mark as published",
+ confirmation="Are you sure you want to mark this article as published ?",
+ icon_class="fas fa-check-circle",
+ submit_btn_text="Yes, proceed",
+ submit_btn_class="btn-success",
+ action_btn_class="btn-info",
+)
+async def make_published_row_action(self, request: Request, pk: Any) -> str:
+ session: Session = request.state.session
+ article = await self.find_by_pk(request, pk)
+ if article.status == Status.Published:
+ raise ActionFailed("The article is already marked as published.")
+ article.status = Status.Published
+ session.add(article)
+ session.commit()
+ return f"The article was successfully marked as published."
+
starlette_admin/actions.py
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 |
|
link_row_action(name, text, action_btn_class=None, icon_class=None, exclude_from_list=False, exclude_from_detail=False)
+
+Decorator to add custom row link actions to a ModelView for URL redirection.
+Note
+This decorator is designed to create row actions that redirect to a URL, making it ideal for cases where a +row action should simply navigate users to a website or internal page.
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ name
+ |
+
+ str
+ |
+
+
+
+ Unique row action name for the ModelView. + |
+ + required + | +
+ text
+ |
+
+ str
+ |
+
+
+
+ Action text displayed to users. + |
+ + required + | +
+ action_btn_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Action button variant for detail page (ex. |
+
+ None
+ |
+
+ icon_class
+ |
+
+ Optional[str]
+ |
+
+
+
+ Icon class (ex. |
+
+ None
+ |
+
+ exclude_from_list
+ |
+
+ bool
+ |
+
+
+
+ Set to True to exclude the action from the list view. + |
+
+ False
+ |
+
+ exclude_from_detail
+ |
+
+ bool
+ |
+
+
+
+ Set to True to exclude the action from the detail view. + |
+
+ False
+ |
+
Usage
+ +starlette_admin/actions.py
starlette_admin.auth
+
+
+BaseAuthProvider
+
+
+
+ Bases: ABC
Base class for implementing the Authentication into your admin interface
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ login_path
+ |
+
+ str
+ |
+
+
+
+ The path for the login page. + |
+
+ '/login'
+ |
+
+ logout_path
+ |
+
+ str
+ |
+
+
+
+ The path for the logout page. + |
+
+ '/logout'
+ |
+
+ allow_paths
+ |
+
+ Optional[Sequence[str]]
+ |
+
+
+
+ A list of paths that are allowed without authentication. + |
+
+ None
+ |
+
+ allow_routes
+ |
+
+ Optional[Sequence[str]]
+ |
+
+
+
+ A list of route names that are allowed without authentication. + |
+
+ None
+ |
+
allow_paths
is deprecated. It is recommended to use allow_routes
+ that specifies the route names instead.starlette_admin/auth.py
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 |
|
get_admin_config(request)
+
+Override this method to display custom logo_url
and/or app_title
Returns:
+Name | Type | +Description | +
---|---|---|
AdminConfig |
+ Optional[AdminConfig]
+ |
+
+
+
+ The admin interface config + |
+
Examples:
+def get_admin_config(self, request: Request) -> AdminConfig:
+ user = request.state.user # Retrieve current user (previously saved in the request state)
+ return AdminConfig(
+ logo_url=request.url_for("static", path=user["company_logo_url"]),
+ )
+
def get_admin_config(self, request: Request) -> AdminConfig:
+ user = request.state.user # Retrieve current user (previously saved in the request state)
+ return AdminConfig(
+ app_title="Hello, " + user["name"] + "!",
+ )
+
starlette_admin/auth.py
get_admin_user(request)
+
+Override this method to display connected user name
and/or profile
Returns:
+Name | Type | +Description | +
---|---|---|
AdminUser |
+ Optional[AdminUser]
+ |
+
+
+
+ The connected user info + |
+
Examples:
+def get_admin_user(self, request: Request) -> AdminUser:
+ user = request.state.user # Retrieve current user (previously saved in the request state)
+ return AdminUser(username=user["name"], photo_url=user["photo_url"])
+
starlette_admin/auth.py
get_middleware(admin)
+
+This method returns the authentication middleware required for the admin interface +to enable authentication
+ +starlette_admin/auth.py
is_authenticated(request)
+
+
+ async
+
+
+This method will be called to validate each incoming request. +You can also save the connected user information into the +request state and use it later to restrict access to some part +of your admin interface
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
True |
+ bool
+ |
+
+
+
+ to accept the request + |
+
False |
+ bool
+ |
+
+
+
+ to redirect to login page + |
+
Examples:
+async def is_authenticated(self, request: Request) -> bool:
+ if request.session.get("username", None) in users:
+ # Save user object in state
+ request.state.user = my_users_db.get(request.session["username"])
+ return True
+ return False
+
starlette_admin/auth.py
setup_admin(admin)
+
+
+ abstractmethod
+
+
+This method is an abstract method that must be implemented in subclasses. +It allows custom configuration and setup of the admin interface +related to authentication and authorization.
+ +starlette_admin/auth.py
AuthProvider
+
+
+
+ Bases: BaseAuthProvider
starlette_admin/auth.py
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 |
|
get_login_route(admin)
+
+Get the login route for the admin interface.
+ +starlette_admin/auth.py
get_logout_route(admin)
+
+Get the logout route for the admin interface.
+ +starlette_admin/auth.py
login(username, password, remember_me, request, response)
+
+
+ async
+
+
+This method will be called to validate user credentials
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
response |
+ Response
+ |
+
+
+
+ return the response back + |
+
Raises:
+Type | +Description | +
---|---|
+ FormValidationError
+ |
+
+
+
+ when form values is not valid + |
+
+ LoginFailed
+ |
+
+
+
+ to display general error + |
+
Examples:
+async def login(
+ self,
+ username: str,
+ password: str,
+ remember_me: bool,
+ request: Request,
+ response: Response,
+) -> Response:
+ if len(username) < 3:
+ # Form data validation
+ raise FormValidationError(
+ {"username": "Ensure username has at least 03 characters"}
+ )
+
+ if username in my_users_db and password == "password":
+ # Save username in session
+ request.session.update({"username": username})
+ return response
+
+ raise LoginFailed("Invalid username or password")
+
starlette_admin/auth.py
logout(request, response)
+
+
+ async
+
+
+Implement logout logic (clear sessions, cookies, ...) here +and return the response back
+ + +Returns:
+Name | Type | +Description | +
---|---|---|
response |
+ Response
+ |
+
+
+
+ return the response back + |
+
Examples:
+async def logout(self, request: Request, response: Response) -> Response:
+ request.session.clear()
+ return response
+
starlette_admin/auth.py
render_login(request, admin)
+
+
+ async
+
+
+Render the default login page for username & password authentication.
+ +starlette_admin/auth.py
render_logout(request, admin)
+
+
+ async
+
+
+Render the default logout page.
+ +starlette_admin/auth.py
setup_admin(admin)
+
+Set up the admin interface by adding necessary middleware and routes.
+ +starlette_admin/auth.py
login_not_required(endpoint)
+
+Decorators for endpoints that do not require login.
+ +starlette_admin/auth.py
Base class for implementing Admin interface.
+ + + + + + +starlette_admin/base.py
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 +479 +480 +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 |
|
__init__(title=_('Admin'), base_url='/admin', route_name='admin', logo_url=None, login_logo_url=None, templates_dir='templates', statics_dir=None, index_view=None, auth_provider=None, middlewares=None, debug=False, i18n_config=None, favicon_url=None)
+
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ title
+ |
+
+ str
+ |
+
+
+
+ Admin title. + |
+
+ lazy_gettext('Admin')
+ |
+
+ base_url
+ |
+
+ str
+ |
+
+
+
+ Base URL for Admin interface. + |
+
+ '/admin'
+ |
+
+ route_name
+ |
+
+ str
+ |
+
+
+
+ Mounted Admin name + |
+
+ 'admin'
+ |
+
+ logo_url
+ |
+
+ Optional[str]
+ |
+
+
+
+ URL of logo to be displayed instead of title. + |
+
+ None
+ |
+
+ login_logo_url
+ |
+
+ Optional[str]
+ |
+
+
+
+ If set, it will be used for login interface instead of logo_url. + |
+
+ None
+ |
+
+ templates_dir
+ |
+
+ str
+ |
+
+
+
+ Templates dir for customisation + |
+
+ 'templates'
+ |
+
+ statics_dir
+ |
+
+ Optional[str]
+ |
+
+
+
+ Statics dir for customisation + |
+
+ None
+ |
+
+ index_view
+ |
+
+ Optional[CustomView]
+ |
+
+
+
+ CustomView to use for index page. + |
+
+ None
+ |
+
+ auth_provider
+ |
+
+ Optional[BaseAuthProvider]
+ |
+
+
+
+ Authentication Provider + |
+
+ None
+ |
+
+ middlewares
+ |
+
+ Optional[Sequence[Middleware]]
+ |
+
+
+
+ Starlette middlewares + |
+
+ None
+ |
+
+ i18n_config
+ |
+
+ Optional[I18nConfig]
+ |
+
+
+
+ i18n configuration + |
+
+ None
+ |
+
+ favicon_url
+ |
+
+ Optional[str]
+ |
+
+
+
+ URL of favicon. + |
+
+ None
+ |
+
starlette_admin/base.py
add_view(view)
+
+Add View to the Admin interface.
+ +starlette_admin/base.py
custom_render_js(request)
+
+Override this function to provide a link to custom js to override the
+global render
object in javascript which is use to render fields in
+list page.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ Starlette Request + |
+ + required + | +
starlette_admin/base.py
+ Bases: BaseModelView
A view for managing SQLAlchemy models.
+ + + + + + +starlette_admin/contrib/sqla/view.py
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 +479 +480 +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 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 +598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 |
|
sortable_field_mapping: Dict[str, InstrumentedAttribute] = {}
+
+
+ class-attribute
+
+
+A dictionary for overriding the default model attribute used for sorting.
+ + +class Post(Base):
+ __tablename__ = "post"
+
+ id: Mapped[int] = mapped_column(primary_key=True)
+ title: Mapped[str] = mapped_column()
+ user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
+ user: Mapped[User] = relationship(back_populates="posts")
+
+
+class PostView(ModelView):
+ sortable_field = ["id", "title", "user"]
+ sortable_field_mapping = {
+ "user": User.age, # Sort by the age of the related user
+ }
+
get_count_query(request)
+
+Return a Select expression which is used as base statement for +count method.
+ + +Examples:
+class PostView(ModelView):
+
+ def get_list_query(self, request: Request):
+ return super().get_list_query().where(Post.published == true())
+
+ def get_count_query(self, request: Request):
+ return super().get_count_query().where(Post.published == true())
+
starlette_admin/contrib/sqla/view.py
get_list_query(request)
+
+Return a Select expression which is used as base statement for +find_all method.
+ + +Examples:
+class PostView(ModelView):
+
+ def get_list_query(self, request: Request):
+ return super().get_list_query().where(Post.published == true())
+
+ def get_count_query(self, request: Request):
+ return super().get_count_query().where(Post.published == true())
+
If you override this method, don't forget to also override +get_count_query, +for displaying the correct item count in the list view.
+ +starlette_admin/contrib/sqla/view.py
get_search_query(request, term)
+
+Return SQLAlchemy whereclause to use for full text search
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ Starlette request + |
+ + required + | +
+ term
+ |
+
+ str
+ |
+
+
+
+ Filtering term + |
+ + required + | +
Examples:
+class PostView(ModelView):
+
+ def get_search_query(self, request: Request, term: str):
+ return Post.title.contains(term)
+
starlette_admin/contrib/sqla/view.py
validate(request, data)
+
+
+ async
+
+
+Inherit this method to validate your data.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ Starlette request + |
+ + required + | +
+ data
+ |
+
+ Dict[str, Any]
+ |
+
+
+
+ Submitted data + |
+ + required + | +
Raises:
+Type | +Description | +
---|---|
+ FormValidationError
+ |
+
+
+
+ to display errors to users + |
+
Examples:
+from starlette_admin.contrib.sqla import ModelView
+from starlette_admin.exceptions import FormValidationError
+
+
+class Post(Base):
+ __tablename__ = "post"
+
+ id = Column(Integer, primary_key=True)
+ title = Column(String(100), nullable=False)
+ text = Column(Text, nullable=False)
+ date = Column(Date)
+
+
+class PostView(ModelView):
+
+ async def validate(self, request: Request, data: Dict[str, Any]) -> None:
+ errors: Dict[str, str] = dict()
+ _2day_from_today = date.today() + timedelta(days=2)
+ if data["title"] is None or len(data["title"]) < 3:
+ errors["title"] = "Ensure this value has at least 03 characters"
+ if data["text"] is None or len(data["text"]) < 10:
+ errors["text"] = "Ensure this value has at least 10 characters"
+ if data["date"] is None or data["date"] < _2day_from_today:
+ errors["date"] = "We need at least one day to verify your post"
+ if len(errors) > 0:
+ raise FormValidationError(errors)
+ return await super().validate(request, data)
+
starlette_admin/contrib/sqla/view.py
starlette_admin.fields
+
+
+BaseField
+
+
+
+ dataclass
+
+
+Base class for fields
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ name
+ |
+
+ str
+ |
+
+
+
+ Field name, same as attribute name in your model + |
+ + required + | +
+ label
+ |
+
+ Optional[str]
+ |
+
+
+
+ Field label + |
+
+ None
+ |
+
+ help_text
+ |
+
+ Optional[str]
+ |
+
+
+
+ Hint message to display in forms + |
+
+ None
+ |
+
+ type
+ |
+
+ Optional[str]
+ |
+
+
+
+ Field type, unique key used to define the field + |
+
+ None
+ |
+
+ disabled
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Disabled in forms + |
+
+ False
+ |
+
+ read_only
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Read only in forms + |
+
+ False
+ |
+
+ id
+ |
+
+ str
+ |
+
+
+
+ Unique id, used to represent field instance + |
+
+ ''
+ |
+
+ search_builder_type
+ |
+
+ Optional[str]
+ |
+
+
+
+ datatable columns.searchBuilderType, For more information +click here + |
+
+ 'default'
+ |
+
+ required
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Indicate if the fields is required + |
+
+ False
+ |
+
+ exclude_from_list
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Control field visibility in list page + |
+
+ False
+ |
+
+ exclude_from_detail
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Control field visibility in detail page + |
+
+ False
+ |
+
+ exclude_from_create
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Control field visibility in create page + |
+
+ False
+ |
+
+ exclude_from_edit
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Control field visibility in edit page + |
+
+ False
+ |
+
+ searchable
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Indicate if the fields is searchable + |
+
+ True
+ |
+
+ orderable
+ |
+
+ Optional[bool]
+ |
+
+
+
+ Indicate if the fields is orderable + |
+
+ True
+ |
+
+ render_function_key
+ |
+
+ str
+ |
+
+
+
+ Render function key inside the global |
+
+ 'text'
+ |
+
+ form_template
+ |
+
+ str
+ |
+
+
+
+ template for rendering this field in creation and edit page + |
+
+ 'forms/input.html'
+ |
+
+ display_template
+ |
+
+ str
+ |
+
+
+
+ template for displaying this field in detail page + |
+
+ 'displays/text.html'
+ |
+
starlette_admin/fields.py
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 |
|
additional_css_links(request, action)
+
+Returns a list of CSS file URLs to include for the current request action.
+ + +additional_js_links(request, action)
+
+Returns a list of JavaScript file URLs to include for the current request action.
+ + +dict()
+
+input_params()
+
+Return HTML input parameters as a string.
+ + +parse_form_data(request, form_data, action)
+
+
+ async
+
+
+Extracts the value of this field from submitted form data.
+ + +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
.
+However, this function can be overridden to provide custom logic for computing the value of a field.
# 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")]
+
starlette_admin/fields.py
serialize_none_value(request, action)
+
+
+ async
+
+
+Formats a None value for sending to the frontend.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The current request object. + |
+ + required + | +
+ action
+ |
+
+ RequestAction
+ |
+
+
+
+ The current request action. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
Any |
+ Any
+ |
+
+
+
+ The formatted None value. + |
+
starlette_admin/fields.py
serialize_value(request, value, action)
+
+
+ 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.API
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The current request object. + |
+ + required + | +
+ value
+ |
+
+ Any
+ |
+
+
+
+ The value to format. + |
+ + required + | +
+ action
+ |
+
+ RequestAction
+ |
+
+
+
+ The current request action. + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
Any |
+ Any
+ |
+
+
+
+ The formatted value. + |
+
starlette_admin/fields.py
BooleanField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field displays the true/false
value of a boolean property.
starlette_admin/fields.py
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.
+ + + + + + +starlette_admin/fields.py
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.
+ + + + + + +starlette_admin/fields.py
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.
+ + + + + + +starlette_admin/fields.py
StringField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field is used to represent any kind of short text content.
+ + + + + + +starlette_admin/fields.py
TextAreaField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
This field is used to represent any kind of long text content. +For short text contents, use StringField
+ + + + + + +starlette_admin/fields.py
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
+ |
+
+ Union[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()
+ |
+
starlette_admin/fields.py
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 |
|
extra_options: Dict[str, Any] = dc_field(default_factory=dict)
+
+
+ class-attribute
+ instance-attribute
+
+
+For more options, see the TinyMCE | Documentation
+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.
starlette_admin/fields.py
EmailField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
This field is used to represent a text content +that stores a single email address.
+ + + + + + +starlette_admin/fields.py
URLField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
This field is used to represent a text content that stores a single URL.
+ + + + + + +starlette_admin/fields.py
PhoneField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A StringField, except renders an <input type="phone">
.
starlette_admin/fields.py
ColorField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A StringField, except renders an <input type="color">
.
starlette_admin/fields.py
PasswordField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A StringField, except renders an <input type="password">
.
starlette_admin/fields.py
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")],
+ )
+ ]
+```
+
starlette_admin/fields.py
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 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 +598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 +614 +615 +616 +617 +618 +619 +620 +621 +622 +623 +624 +625 +626 +627 +628 +629 +630 +631 +632 +633 +634 +635 +636 +637 +638 +639 +640 +641 +642 +643 +644 +645 +646 +647 +648 +649 +650 +651 +652 +653 +654 +655 |
|
TimeZoneField
+
+
+
+ dataclass
+
+
+
+ Bases: EnumField
This field is used to represent the name of a timezone (eg. Africa/Porto-Novo)
+ + + + + + +starlette_admin/fields.py
CountryField
+
+
+
+ dataclass
+
+
+
+ Bases: EnumField
This field is used to represent the name that corresponds to the country code stored in your database
+ + + + + + +starlette_admin/fields.py
CurrencyField
+
+
+
+ dataclass
+
+
+
+ Bases: EnumField
This field is used to represent a value that stores the +3-letter ISO 4217 code of currency
+ + + + + + +starlette_admin/fields.py
DateTimeField
+
+
+
+ dataclass
+
+
+
+ Bases: NumberField
This field is used to represent a value that stores a python datetime.datetime object +Parameters: + search_format: moment.js format to send for searching. Use None for iso Format + output_format: display output format
+ + + + + + +starlette_admin/fields.py
703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 +717 +718 +719 +720 +721 +722 +723 +724 +725 +726 +727 +728 +729 +730 +731 +732 +733 +734 +735 +736 +737 +738 +739 +740 +741 +742 +743 +744 +745 +746 +747 +748 +749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 +763 +764 +765 +766 +767 +768 +769 +770 +771 +772 +773 +774 +775 +776 +777 +778 +779 +780 +781 +782 +783 +784 +785 +786 +787 |
|
DateField
+
+
+
+ dataclass
+
+
+
+ Bases: DateTimeField
This field is used to represent a value that stores a python datetime.date object +Parameters: + search_format: moment.js format to send for searching. Use None for iso Format + output_format: Set display output format
+ + + + + + +starlette_admin/fields.py
TimeField
+
+
+
+ dataclass
+
+
+
+ Bases: DateTimeField
This field is used to represent a value that stores a python datetime.time object +Parameters: + search_format: Format to send for search. Use None for iso Format + output_format: Set display output format
+ + + + + + +starlette_admin/fields.py
ArrowField
+
+
+
+ dataclass
+
+
+
+ Bases: DateTimeField
This field is used to represent sqlalchemy_utils.types.arrow.ArrowType
+ + + + + + +starlette_admin/fields.py
JSONField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field render jsoneditor and represent a value that stores python dict object. +Erroneous input is ignored and will not be accepted as a value.
+ + + + + + +starlette_admin/fields.py
FileField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
Renders a file upload field.
+This field is used to represent a value that stores starlette UploadFile object.
+For displaying value, this field wait for three properties which is filename
,
+content-type
and url
. Use multiple=True
for multiple file upload
+When user ask for delete on editing page, the second part of the returned tuple is True.
starlette_admin/fields.py
ImageField
+
+
+
+ dataclass
+
+
+
+ Bases: FileField
FileField with accept="image/*"
.
starlette_admin/fields.py
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 in your admin interface.
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ identity
+ |
+
+ Optional[str]
+ |
+
+
+
+ Foreign ModelView identity + |
+
+ None
+ |
+
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", identity="book"),
+ ]
+
+class BookView(ModelView):
+ fields = [
+ IntegerField("id"),
+ StringField("title"),
+ HasOne("author", identity="author"),
+ ]
+...
+admin.add_view(AuthorView(Author, identity="author"))
+admin.add_view(BookView(Book, identity="book"))
+...
+
starlette_admin/fields.py
995 + 996 + 997 + 998 + 999 +1000 +1001 +1002 +1003 +1004 +1005 +1006 +1007 +1008 +1009 +1010 +1011 +1012 +1013 +1014 +1015 +1016 +1017 +1018 +1019 +1020 +1021 +1022 +1023 +1024 +1025 +1026 +1027 +1028 +1029 +1030 +1031 +1032 +1033 +1034 +1035 +1036 +1037 +1038 +1039 +1040 +1041 +1042 +1043 +1044 +1045 +1046 +1047 +1048 +1049 +1050 +1051 +1052 +1053 +1054 +1055 +1056 +1057 +1058 +1059 +1060 +1061 +1062 +1063 +1064 +1065 +1066 +1067 +1068 +1069 +1070 +1071 +1072 +1073 +1074 +1075 +1076 +1077 +1078 +1079 +1080 +1081 +1082 |
|
HasOne
+
+
+
+ dataclass
+
+
+
+ Bases: RelationField
A field representing a "has-one" relation between two models.
+ + + + + + +starlette_admin/fields.py
HasMany
+
+
+
+ dataclass
+
+
+
+ Bases: RelationField
A field representing a "has-many" relationship between two models.
+ + + + + + +starlette_admin/fields.py
ListField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
Encapsulate an ordered list of multiple instances of the same field type, +keeping data as a list.
+Usage
+ +starlette_admin/fields.py
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 +1249 +1250 +1251 +1252 +1253 +1254 +1255 +1256 +1257 +1258 +1259 +1260 +1261 +1262 +1263 +1264 +1265 +1266 +1267 +1268 +1269 |
|
CollectionField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field represents a collection of others fields. Can be used to represent embedded mongodb document.
+Usage
+ CollectionField("config", fields=[StringField("key"), IntegerField("value", help_text="multiple of 5")]),
+
starlette_admin/fields.py
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 |
|
starlette_admin.views
+
+
+BaseView
+
+
+Base class for all views
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
label |
+
+ str
+ |
+
+
+
+ Label of the view to be displayed. + |
+
icon |
+
+ Optional[str]
+ |
+
+
+
+ Icon to be displayed for this model in the admin. Only FontAwesome names are supported. + |
+
starlette_admin/views.py
is_accessible(request)
+
+Override this method to add permission checks. +Return True if current user can access this view
+ + +is_active(request)
+
+title(request)
+
+DropDown
+
+
+
+ Bases: BaseView
Group views inside a dropdown
+ + +starlette_admin/views.py
Link
+
+
+
+ Bases: BaseView
Add arbitrary hyperlinks to the menu
+ + + + + + + + +starlette_admin/views.py
CustomView
+
+
+
+ Bases: BaseView
Add your own views (not tied to any particular model). For example, +a custom home page that displays some analytics data.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
path |
+ + | +
+
+
+ Route path + |
+
template_path |
+ + | +
+
+
+ Path to template file + |
+
methods |
+ + | +
+
+
+ HTTP methods + |
+
name |
+ + | +
+
+
+ Route name + |
+
add_to_menu |
+ + | +
+
+
+ Display to menu or not + |
+
starlette_admin/views.py
render(request, templates)
+
+
+ async
+
+
+Default methods to render view. Override this methods to add your custom logic.
+ +starlette_admin/views.py
BaseModelView
+
+
+
+ Bases: BaseView
Base administrative view. +Derive from this class to implement your administrative interface piece.
+ + +Attributes:
+Name | +Type | +Description | +
---|---|---|
identity |
+
+ Optional[str]
+ |
+
+
+
+ Unique identity to identify the model associated to this view. +Will be used for URL of the endpoints. + |
+
name |
+
+ Optional[str]
+ |
+
+
+
+ Name of the view to be displayed + |
+
fields |
+
+ Sequence[BaseField]
+ |
+
+
+
+ List of fields + |
+
pk_attr |
+
+ Optional[str]
+ |
+
+
+
+ Primary key field name + |
+
form_include_pk |
+
+ bool
+ |
+
+
+
+ Indicates whether the primary key should be +included in create and edit forms. Default to False. + |
+
exclude_fields_from_list |
+
+ Sequence[str]
+ |
+
+
+
+ List of fields to exclude in List page. + |
+
exclude_fields_from_detail |
+
+ Sequence[str]
+ |
+
+
+
+ List of fields to exclude in Detail page. + |
+
exclude_fields_from_create |
+
+ Sequence[str]
+ |
+
+
+
+ List of fields to exclude from creation page. + |
+
exclude_fields_from_edit |
+
+ Sequence[str]
+ |
+
+
+
+ List of fields to exclude from editing page. + |
+
searchable_fields |
+
+ Optional[Sequence[str]]
+ |
+
+
+
+ List of searchable fields. + |
+
sortable_fields |
+
+ Optional[Sequence[str]]
+ |
+
+
+
+ List of sortable fields. + |
+
export_fields |
+
+ Optional[Sequence[str]]
+ |
+
+
+
+ List of fields to include in exports. + |
+
fields_default_sort |
+
+ Optional[Sequence[Union[Tuple[str, bool], str]]]
+ |
+
+
+
+ Initial order (sort) to apply to the table.
+Should be a sequence of field names or a tuple of
+(field name, True/False to indicate the sort direction).
+For example:
+ |
+
export_types |
+
+ Sequence[ExportType]
+ |
+
+
+
+ A list of available export filetypes. Available
+exports are |
+
column_visibility |
+
+ bool
+ |
+
+
+
+ Enable/Disable +column visibility +extension + |
+
search_builder |
+
+ bool
+ |
+
+
+
+ Enable/Disable search builder +extension + |
+
page_size |
+
+ int
+ |
+
+
+
+ Default number of items to display in List page pagination.
+Default value is set to |
+
page_size_options |
+
+ Sequence[int]
+ |
+
+
+
+ Pagination choices displayed in List page.
+Default value is set to |
+
responsive_table |
+
+ bool
+ |
+
+
+
+ Enable/Disable responsive +extension + |
+
save_state |
+
+ bool
+ |
+
+
+
+ Enable/Disable state saving + |
+
datatables_options |
+
+ Dict[str, Any]
+ |
+
+
+
+ Dict of Datatables options. +These will overwrite any default options set for the datatable. + |
+
list_template |
+
+ str
+ |
+
+
+
+ List view template. Default is |
+
detail_template |
+
+ str
+ |
+
+
+
+ Details view template. Default is |
+
create_template |
+
+ str
+ |
+
+
+
+ Edit view template. Default is |
+
edit_template |
+
+ str
+ |
+
+
+
+ Edit view template. Default is |
+
actions |
+
+ Optional[Sequence[str]]
+ |
+
+
+
+ List of actions + |
+
additional_js_links |
+
+ Optional[List[str]]
+ |
+
+
+
+ A list of additional JavaScript files to include. + |
+
additional_css_links |
+
+ Optional[List[str]]
+ |
+
+
+
+ A list of additional CSS files to include. + |
+
starlette_admin/views.py
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 +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 +588 +589 +590 +591 +592 +593 +594 +595 +596 +597 +598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 +614 +615 +616 +617 +618 +619 +620 +621 +622 +623 +624 +625 +626 +627 +628 +629 +630 +631 +632 +633 +634 +635 +636 +637 +638 +639 +640 +641 +642 +643 +644 +645 +646 +647 +648 +649 +650 +651 +652 +653 +654 +655 +656 +657 +658 +659 +660 +661 +662 +663 +664 +665 +666 +667 +668 +669 +670 +671 +672 +673 +674 +675 +676 +677 +678 +679 +680 +681 +682 +683 +684 +685 +686 +687 +688 +689 +690 +691 +692 +693 +694 +695 +696 +697 +698 +699 +700 +701 +702 +703 +704 +705 +706 +707 +708 +709 +710 +711 +712 +713 +714 +715 +716 +717 +718 +719 +720 +721 +722 +723 +724 +725 +726 +727 +728 +729 +730 +731 +732 +733 +734 +735 +736 +737 +738 +739 +740 +741 +742 +743 +744 +745 +746 +747 +748 +749 +750 +751 +752 +753 +754 +755 +756 +757 +758 +759 +760 +761 +762 +763 +764 +765 +766 +767 +768 +769 +770 +771 +772 +773 +774 +775 +776 +777 +778 +779 +780 +781 +782 +783 +784 +785 +786 +787 +788 +789 +790 +791 +792 +793 +794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809 +810 +811 +812 +813 +814 +815 +816 +817 +818 +819 +820 +821 +822 +823 +824 +825 +826 +827 +828 +829 +830 +831 +832 +833 +834 +835 +836 +837 +838 +839 +840 +841 +842 +843 +844 +845 +846 +847 +848 +849 +850 +851 +852 +853 +854 +855 +856 +857 +858 +859 +860 +861 +862 +863 +864 +865 +866 +867 +868 +869 +870 +871 +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 +949 +950 +951 +952 +953 +954 +955 +956 +957 +958 +959 +960 +961 +962 +963 +964 +965 +966 +967 +968 +969 +970 +971 +972 +973 +974 +975 +976 +977 +978 +979 +980 +981 +982 +983 +984 |
|
after_create(request, obj)
+
+
+ async
+
+
+This hook is called after a new item is successfully created.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The newly created object. + |
+ + required + | +
starlette_admin/views.py
after_delete(request, obj)
+
+
+ async
+
+
+This hook is called after an item is successfully deleted.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The deleted object. + |
+ + required + | +
starlette_admin/views.py
after_edit(request, obj)
+
+
+ async
+
+
+This hook is called after an item is successfully edited.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The edited object. + |
+ + required + | +
before_create(request, data, obj)
+
+
+ async
+
+
+This hook is called before a new item is created.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ data
+ |
+
+ Dict[str, Any]
+ |
+
+
+
+ Dict values contained converted form data. + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The object about to be created. + |
+ + required + | +
starlette_admin/views.py
before_delete(request, obj)
+
+
+ async
+
+
+This hook is called before an item is deleted.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The object about to be deleted. + |
+ + required + | +
starlette_admin/views.py
before_edit(request, data, obj)
+
+
+ async
+
+
+This hook is called before an item is edited.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ data
+ |
+
+ Dict[str, Any]
+ |
+
+
+
+ Dict values contained converted form data + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The object about to be edited. + |
+ + required + | +
starlette_admin/views.py
can_create(request)
+
+can_delete(request)
+
+can_edit(request)
+
+can_view_details(request)
+
+count(request, where=None)
+
+
+ abstractmethod
+ async
+
+
+Count items +Parameters: + request: The request being processed + where: Can be dict for complex query +
+ or plain text for full search + +starlette_admin/views.py
create(request, data)
+
+
+ abstractmethod
+ async
+
+
+Create item +Parameters: + request: The request being processed + data: Dict values contained converted form data +Returns: + Any: Created Item
+ +starlette_admin/views.py
delete(request, pks)
+
+
+ abstractmethod
+ async
+
+
+Bulk delete items +Parameters: + request: The request being processed + pks: List of primary keys
+ +starlette_admin/views.py
edit(request, pk, data)
+
+
+ abstractmethod
+ async
+
+
+Edit item +Parameters: + request: The request being processed + pk: Primary key + data: Dict values contained converted form data +Returns: + Any: Edited Item
+ +starlette_admin/views.py
find_all(request, skip=0, limit=100, where=None, order_by=None)
+
+
+ abstractmethod
+ async
+
+
+Find all items +Parameters: + request: The request being processed + where: Can be dict for complex query +
+ or plain text for full search + skip: should return values start from position skip+1 + limit: number of maximum items to return + order_by: order data clauses in form["id asc", "name desc"]
+
+ starlette_admin/views.py
find_by_pk(request, pk)
+
+
+ abstractmethod
+ async
+
+
+Find one item +Parameters: + request: The request being processed + pk: Primary key
+ + +find_by_pks(request, pks)
+
+
+ abstractmethod
+ async
+
+
+Find many items +Parameters: + request: The request being processed + pks: List of Primary key
+ +starlette_admin/views.py
get_all_actions(request)
+
+
+ async
+
+
+Return a list of allowed batch actions
+ +starlette_admin/views.py
get_all_row_actions(request)
+
+
+ async
+
+
+Return a list of allowed row actions
+ +starlette_admin/views.py
get_fields_list(request, action=RequestAction.LIST)
+
+Return a list of field instances to display in the specified view action.
+This function excludes fields with corresponding exclude flags, which are
+determined by the exclude_fields_from_*
attributes.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed. + |
+ + required + | +
+ action
+ |
+
+ RequestAction
+ |
+
+
+
+ The type of action being performed on the view. + |
+
+ LIST
+ |
+
starlette_admin/views.py
get_serialized_pk_value(request, obj)
+
+
+ async
+
+
+Return serialized value of the primary key.
+Note
+The returned value should be JSON-serializable.
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
+ obj
+ |
+
+ Any
+ |
+
+
+
+ object to get primary key of + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
Any |
+ Any
+ |
+
+
+
+ Serialized value of a PK. + |
+
starlette_admin/views.py
handle_action(request, pks, name)
+
+
+ async
+
+
+Handle action with name
.
+Raises:
+ ActionFailed: to display meaningfully error
starlette_admin/views.py
handle_row_action(request, pk, name)
+
+
+ async
+
+
+Handle row action with name
.
+Raises:
+ ActionFailed: to display meaningfully error
starlette_admin/views.py
is_action_allowed(request, name)
+
+
+ async
+
+
+Verify if action with name
is allowed.
+Override this method to allow or disallow actions based
+on some condition.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ name
+ |
+
+ str
+ |
+
+
+
+ Action name + |
+ + required + | +
+ request
+ |
+
+ Request
+ |
+
+
+
+ Starlette request + |
+ + required + | +
starlette_admin/views.py
is_row_action_allowed(request, name)
+
+
+ async
+
+
+Verify if the row action with name
is allowed.
+Override this method to allow or disallow row actions based
+on some condition.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ name
+ |
+
+ str
+ |
+
+
+
+ Row action name + |
+ + required + | +
+ request
+ |
+
+ Request
+ |
+
+
+
+ Starlette request + |
+ + required + | +
starlette_admin/views.py
repr(obj, request)
+
+
+ async
+
+
+Return a string representation of the given object that can be displayed in the admin interface.
+If the object has a custom representation method __admin_repr__
, it is used to generate the string. Otherwise,
+the value of the object's primary key attribute is used.
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The object to represent. + |
+ + required + | +
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
For example, the following implementation for a User
model will display
+the user's full name instead of their primary key in the admin interface:
starlette_admin/views.py
select2_result(obj, request)
+
+
+ async
+
+
+Returns an HTML-formatted string that represents the search results for a Select2 search box.
+By default, this method returns a string that contains all the object's attributes in a list except +relation and file attributes.
+If the object has a custom representation method __admin_select2_repr__
, it is used to generate the
+HTML-formatted string.
Note
+The returned value should be valid HTML.
+Danger
+Escape your database value to avoid Cross-Site Scripting (XSS) attack.
+You can use Jinja2 Template render with autoescape=True
.
+For more information click here
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ obj
+ |
+
+ Any
+ |
+
+
+
+ The object returned by the |
+ + required + | +
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
Here is an example implementation for a User
model
+that includes the user's name and photo:
starlette_admin/views.py
select2_selection(obj, request)
+
+
+ async
+
+
+Returns the HTML representation of an item selected by a user in a Select2 component.
+By default, it simply calls select2_result()
.
Note
+The returned value should be valid HTML.
+Danger
+Escape your database value to avoid Cross-Site Scripting (XSS) attack.
+You can use Jinja2 Template render with autoescape=True
.
+For more information click here
Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ obj
+ |
+
+ Any
+ |
+
+
+
+ item returned by |
+ + required + | +
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
starlette_admin/views.py
serialize_field_value(value, field, action, request)
+
+
+ async
+
+
+Format output value for each field.
+Important
+The returned value should be json serializable
+Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ value
+ |
+
+ Any
+ |
+
+
+
+ attribute of item returned by |
+ + required + | +
+ field
+ |
+
+ BaseField
+ |
+
+
+
+ Starlette Admin field for this attribute + |
+ + required + | +
+ action
+ |
+
+ RequestAction
+ |
+
+
+
+ Specify where the data will be used. Possible values are
+ |
+ + required + | +
+ request
+ |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
starlette_admin/views.py
9nB-pv`!e7zAP|2my-oW1bI%l~!gEyMXCbO(iOt*+i2%zyQ0ZZ?R9
z-E}%sh&oB(or8}ffun*QXMd-GA84<<=|VHUnXPrx(Rq4v2;U?)+BX#b?cxSW{C0yp
z{ypzHe`>oy7yldCn?}J+qv-GH*Kz0O!gLZ>4rp9Z-Fc}w);ePIhwYJt#xoe&|Mu;p
z|F;*8u2Y|XBq-tk(&@R0Z+{u@zg|!XxNF=J#Ss^~zpVg>r)zapVJ_84Kq348NxN)F
z2iP<0LI0YWg%ez2fs8T!C9SDfLLTn20vQK;#(#E&cm&) Z#Mhy~|d9TT+
ziuJLJP+@U)Z=ud-Y;AH~;o+B$#b^D2c}ZBd5`PqOe{YU5u4c;CI9%Mp;ry00*l(`~
zd3yLds#UdtgLh~rmNGWaK1nT;lJ=q8SDG{RyBa}U!IXg&x_8}>9|||Tg;%azqe}&I
zrRhLJ1W<>8e*jDK8X`h-sG78+hy=%xpNJ#nV;^BI8=+^4Om;QX={?nw6wWX5VbTE0
zZ6)R-*72&*S|5S0g80nqWiI{ZGjqupDSYBt>S`z-gpIs6P 6@MAUa;aixuYr}b=6W%a=kiOw+%uNr!dt=ufb>g=4Z;|B(jDUV@+ub;oH
ziO6Zc64!V=rKRrOzyP7&JFyAZ*LM~926n*-p4;BybEChzHz)t)r6{z3 3@#
z>X2uuw<%}I(?}%3cWEV<^`r=W7Kbi(e5?bd9?sQa`Jo{h^a58EC38mz!0SF$vkMaE
zz-E&H%XGWF@DtN6-$AA^!G*r0hyqrTqxi?C(}+fKbj$DQL9d4$1*2!uF6@=2|4ti4
z)a&;1P_JPx%aiLW=qTe+eOm)saGb}_iMszRxt^h86(SfbP9E8u)xwT|u`j0Qzl_G~
zcf3I)hTEx#?VL)9qWt5nwKT#A64?4O!eapR)hcSdB{&lewBo+ldT+Np4ot<3NaJGl
zj_gAXQ|k$#(&*!B_DD}55l%(DU(x(1VSI@;LWKDgB*I2tm_z%i?sj`I&-f9B6c?U&
zNdH^`Oq%u-rIK(jIyxescSPC=4L0z++jwWt#nix4R(3i;d~~wUitb$)vVZv^tL|sx
zA}vHGTg6b(jqj9jukwK8nTt}#KHs-gjI?TQxDUwzZ4NK%6P-%}+&}vq46MwkAtp7>
z4#9NwRR
zQ2)C0IAh=d)0#z!4|;<-#5Dj2yCD(p2@yEhX7M@9!skG{06>gID*nI%o2I=ZzEK3g
z!pR&xUHTYE0={>{6CiBZqk6lSd9Z0ZJ0lQyN(2ze0~=jxAG-jR;jF9!;B9)T7GJTy)6h1&pR
zJ5%_P5_pjEr-?Y8FG(BMicFdeC8U~nYUO98Sd3JFy;+^7wp+WUSXM
&_emngO}`GN-~@o()N7#MS5XhR!ICj+;K?KBBfV&xR==&Lm=E
zgQ-