From dcb0cf3e824e9e3e07414340dbb9414649cede83 Mon Sep 17 00:00:00 2001 From: <> Date: Wed, 23 Aug 2023 04:18:29 +0000 Subject: [PATCH] Deployed e7eb98b with MkDocs version: 1.5.2 --- .nojekyll | 0 404.html | 1185 +++ advanced/base-model-view/index.html | 1580 ++++ advanced/custom-field/index.html | 1507 ++++ alternatives/index.html | 1274 ++++ api/actions/index.html | 1687 +++++ api/auth-provider/index.html | 2896 +++++++ api/base-admin/index.html | 2700 +++++++ api/contrib/sqlalchemy/modelview/index.html | 2699 +++++++ api/fields/index.html | 6458 ++++++++++++++++ api/views/index.html | 5651 ++++++++++++++ assets/_mkdocstrings.css | 64 + assets/images/favicon.png | Bin 0 -> 1870 bytes assets/javascripts/bundle.78eede0e.min.js | 29 + assets/javascripts/bundle.78eede0e.min.js.map | 8 + 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.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.dfff1995.min.js | 42 + .../workers/search.dfff1995.min.js.map | 8 + assets/stylesheets/main.0e669242.min.css | 1 + assets/stylesheets/main.0e669242.min.css.map | 1 + assets/stylesheets/palette.85d0ee34.min.css | 1 + .../stylesheets/palette.85d0ee34.min.css.map | 1 + changelog/index.html | 2790 +++++++ deployment/index.html | 1286 ++++ es/advanced/base-model-view/index.html | 1580 ++++ es/advanced/custom-field/index.html | 1507 ++++ es/alternatives/index.html | 1274 ++++ es/api/actions/index.html | 1687 +++++ es/api/auth-provider/index.html | 2896 +++++++ es/api/base-admin/index.html | 2700 +++++++ .../contrib/sqlalchemy/modelview/index.html | 2699 +++++++ es/api/fields/index.html | 6458 ++++++++++++++++ es/api/views/index.html | 5651 ++++++++++++++ es/changelog/index.html | 2790 +++++++ es/deployment/index.html | 1286 ++++ es/images/preview.jpg | Bin 0 -> 249852 bytes .../modelview/object_text_representation.png | Bin 0 -> 51659 bytes .../modelview/select2_customization.png | Bin 0 -> 85041 bytes es/images/validations/mongoengine.png | Bin 0 -> 95008 bytes es/images/validations/odmantic.png | Bin 0 -> 101537 bytes es/images/validations/sqla.png | Bin 0 -> 121123 bytes es/images/validations/sqlmodel.png | Bin 0 -> 91710 bytes es/index.html | 1498 ++++ es/stylesheets/extra.css | 4 + es/tutorial/authentication/index.html | 1643 ++++ es/tutorial/batch-actions/index.html | 1391 ++++ es/tutorial/configurations/admin/index.html | 1355 ++++ .../configurations/modelview/index.html | 1641 ++++ es/tutorial/files/index.html | 1383 ++++ es/tutorial/getting-started/index.html | 1654 ++++ es/tutorial/multiple-admin/index.html | 1296 ++++ es/tutorial/validations/index.html | 1560 ++++ 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 | 1520 ++++ objects.inv | 9 + search/search_index.json | 1 + sitemap.xml | 163 + sitemap.xml.gz | Bin 0 -> 644 bytes stylesheets/extra.css | 4 + tutorial/authentication/index.html | 1643 ++++ tutorial/batch-actions/index.html | 1391 ++++ tutorial/configurations/admin/index.html | 1355 ++++ tutorial/configurations/modelview/index.html | 1641 ++++ tutorial/files/index.html | 1383 ++++ tutorial/getting-started/index.html | 1654 ++++ tutorial/multiple-admin/index.html | 1296 ++++ tutorial/validations/index.html | 1560 ++++ 105 files changed, 96641 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-provider/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/images/favicon.png create mode 100644 assets/javascripts/bundle.78eede0e.min.js create mode 100644 assets/javascripts/bundle.78eede0e.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.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.dfff1995.min.js create mode 100644 assets/javascripts/workers/search.dfff1995.min.js.map create mode 100644 assets/stylesheets/main.0e669242.min.css create mode 100644 assets/stylesheets/main.0e669242.min.css.map create mode 100644 assets/stylesheets/palette.85d0ee34.min.css create mode 100644 assets/stylesheets/palette.85d0ee34.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-provider/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/images/preview.jpg create mode 100644 es/images/tutorial/configurations/modelview/object_text_representation.png create mode 100644 es/images/tutorial/configurations/modelview/select2_customization.png create mode 100644 es/images/validations/mongoengine.png create mode 100644 es/images/validations/odmantic.png create mode 100644 es/images/validations/sqla.png create mode 100644 es/images/validations/sqlmodel.png create mode 100644 es/index.html create mode 100644 es/stylesheets/extra.css create mode 100644 es/tutorial/authentication/index.html create mode 100644 es/tutorial/batch-actions/index.html create mode 100644 es/tutorial/configurations/admin/index.html create mode 100644 es/tutorial/configurations/modelview/index.html create mode 100644 es/tutorial/files/index.html create mode 100644 es/tutorial/getting-started/index.html create mode 100644 es/tutorial/multiple-admin/index.html create mode 100644 es/tutorial/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 tutorial/authentication/index.html create mode 100644 tutorial/batch-actions/index.html create mode 100644 tutorial/configurations/admin/index.html create mode 100644 tutorial/configurations/modelview/index.html create mode 100644 tutorial/files/index.html create mode 100644 tutorial/getting-started/index.html create mode 100644 tutorial/multiple-admin/index.html create mode 100644 tutorial/validations/index.html diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 000000000..e69de29bb diff --git a/404.html b/404.html new file mode 100644 index 000000000..e8559b080 --- /dev/null +++ b/404.html @@ -0,0 +1,1185 @@ + + + +
+ + + + + + + + + + + + + + + + +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_text=_('Yes, Proceed'), submit_btn_class='btn-primary', form=None, custom_response=False)
+
+Use this decorator to add custom 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'
+ |
+
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 |
|
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
+ |
+
starlette_admin/auth.py
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 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 |
|
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
starlette_admin.auth.AuthProvider
+
+
+
+ Bases: BaseAuthProvider
starlette_admin/auth.py
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 |
|
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)
+
+Setup the admin interface by adding necessary middleware and routes.
+ +starlette_admin/auth.py
starlette_admin.base.BaseAdmin
+
+
+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 |
|
__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)
+
+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
+ |
+
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
starlette_admin.contrib.sqla.ModelView
+
+
+
+ Bases: BaseModelView
starlette_admin/contrib/sqla/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 |
|
get_count_query()
+
+Return a Select expression which is used as base statement for +count method.
+ + + +Examples:
+class PostView(ModelView):
+
+ def get_list_query(self):
+ return super().get_list_query().where(Post.published == true())
+
+ def get_count_query(self):
+ return super().get_count_query().where(Post.published == true())
+
starlette_admin/contrib/sqla/view.py
get_list_query()
+
+Return a Select expression which is used as base statement for +find_all method.
+ + + +Examples:
+class PostView(ModelView):
+
+ def get_list_query(self):
+ return super().get_list_query().where(Post.published == true())
+
+ def get_count_query(self):
+ 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 |
|
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
starlette_admin.fields.BooleanField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field displays the true/false
value of a boolean property.
starlette_admin/fields.py
starlette_admin.fields.IntegerField
+
+
+
+ dataclass
+
+
+
+ Bases: NumberField
This field is used to represent the value of properties that store integer numbers. +Erroneous input is ignored and will not be accepted as a value.
+ +starlette_admin/fields.py
starlette_admin.fields.DecimalField
+
+
+
+ dataclass
+
+
+
+ Bases: NumberField
This field is used to represent the value of properties that store decimal numbers. +Erroneous input is ignored and will not be accepted as a value.
+ +starlette_admin/fields.py
starlette_admin.fields.FloatField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A text field, except all input is coerced to an float. + Erroneous input is ignored and will not be accepted as a value.
+ +starlette_admin/fields.py
starlette_admin.fields.StringField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field is used to represent any kind of short text content.
+ +starlette_admin/fields.py
starlette_admin.fields.TextAreaField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
This field is used to represent any kind of long text content. +For short text contents, use StringField
+ +starlette_admin/fields.py
starlette_admin.fields.TinyMCEEditorField
+
+
+
+ dataclass
+
+
+
+ Bases: TextAreaField
A field that provides a WYSIWYG editor for long text content using the + TinyMCE library.
+This field can be used as an alternative to the TextAreaField +to provide a more sophisticated editor for user input.
+ +starlette_admin/fields.py
starlette_admin.fields.TagsField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
This field is used to represent the value of properties that store a list of
+string values. Render as select2
tags input.
starlette_admin/fields.py
starlette_admin.fields.EmailField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
This field is used to represent a text content +that stores a single email address.
+ +starlette_admin/fields.py
starlette_admin.fields.URLField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
This field is used to represent a text content that stores a single URL.
+ +starlette_admin/fields.py
starlette_admin.fields.PhoneField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A StringField, except renders an <input type="phone">
.
starlette_admin/fields.py
starlette_admin.fields.ColorField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A StringField, except renders an <input type="color">
.
starlette_admin/fields.py
starlette_admin.fields.PasswordField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
A StringField, except renders an <input type="password">
.
starlette_admin/fields.py
starlette_admin.fields.EnumField
+
+
+
+ dataclass
+
+
+
+ Bases: StringField
Enumeration Field.
+It takes a python enum.Enum
class or a list of (value, label) pairs.
+It can also be a list of only values, in which case the value is used as the label.
starlette_admin/fields.py
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 |
|
starlette_admin.fields.TimeZoneField
+
+
+
+ dataclass
+
+
+
+ Bases: EnumField
This field is used to represent the name of a timezone (eg. Africa/Porto-Novo)
+ +starlette_admin/fields.py
starlette_admin.fields.CountryField
+
+
+
+ dataclass
+
+
+
+ Bases: EnumField
This field is used to represent the name that corresponds to the country code stored in your database
+ +starlette_admin/fields.py
starlette_admin.fields.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
starlette_admin.fields.DateTimeField
+
+
+
+ dataclass
+
+
+
+ Bases: NumberField
This field is used to represent a value that stores a python datetime.datetime object
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
search_format |
+
+ Optional[str]
+ |
+
+
+
+ moment.js format to send for searching. Use None for iso Format + |
+
+ None
+ |
+
output_format |
+
+ Optional[str]
+ |
+
+
+
+ display output format + |
+
+ None
+ |
+
starlette_admin/fields.py
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 |
|
starlette_admin.fields.DateField
+
+
+
+ dataclass
+
+
+
+ Bases: DateTimeField
This field is used to represent a value that stores a python datetime.date object
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
search_format |
+
+ str
+ |
+
+
+
+ moment.js format to send for searching. Use None for iso Format + |
+
+ 'YYYY-MM-DD'
+ |
+
output_format |
+
+ Optional[str]
+ |
+
+
+
+ Set display output format + |
+
+ None
+ |
+
starlette_admin/fields.py
starlette_admin.fields.TimeField
+
+
+
+ dataclass
+
+
+
+ Bases: DateTimeField
This field is used to represent a value that stores a python datetime.time object
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
search_format |
+
+ str
+ |
+
+
+
+ Format to send for search. Use None for iso Format + |
+
+ 'HH:mm:ss'
+ |
+
output_format |
+
+ Optional[str]
+ |
+
+
+
+ Set display output format + |
+
+ None
+ |
+
starlette_admin/fields.py
starlette_admin.fields.ArrowField
+
+
+
+ dataclass
+
+
+
+ Bases: DateTimeField
This field is used to represent sqlalchemy_utils.types.arrow.ArrowType
+ +starlette_admin/fields.py
starlette_admin.fields.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
starlette_admin.fields.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
starlette_admin.fields.ImageField
+
+
+
+ dataclass
+
+
+
+ Bases: FileField
FileField with accept="image/*"
.
starlette_admin/fields.py
starlette_admin.fields.RelationField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
A field representing a relation between two data models.
+This field should not be used directly; instead, use either the HasOne +or HasMany fields to specify a relation +between your models.
+Important
+It is important to add both models 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
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 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 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 |
|
starlette_admin.fields.HasOne
+
+
+
+ dataclass
+
+
+starlette_admin.fields.HasMany
+
+
+
+ dataclass
+
+
+
+ Bases: RelationField
A field representing a "has-many" relationship between two models.
+ +starlette_admin/fields.py
starlette_admin.fields.ListField
+
+
+
+ dataclass
+
+
+
+ Bases: BaseField
Encapsulate an ordered list of multiple instances of the same field type, +keeping data as a list.
+Usage
+ +starlette_admin/fields.py
1135 +1136 +1137 +1138 +1139 +1140 +1141 +1142 +1143 +1144 +1145 +1146 +1147 +1148 +1149 +1150 +1151 +1152 +1153 +1154 +1155 +1156 +1157 +1158 +1159 +1160 +1161 +1162 +1163 +1164 +1165 +1166 +1167 +1168 +1169 +1170 +1171 +1172 +1173 +1174 +1175 +1176 +1177 +1178 +1179 +1180 +1181 +1182 +1183 +1184 +1185 +1186 +1187 +1188 +1189 +1190 +1191 +1192 +1193 +1194 +1195 +1196 +1197 +1198 +1199 +1200 +1201 +1202 +1203 +1204 +1205 +1206 +1207 +1208 +1209 +1210 +1211 +1212 +1213 +1214 +1215 +1216 +1217 +1218 +1219 +1220 +1221 +1222 +1223 +1224 +1225 |
|
starlette_admin.fields.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
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 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099 +1100 +1101 +1102 +1103 +1104 +1105 +1106 +1107 +1108 +1109 +1110 +1111 +1112 +1113 +1114 +1115 +1116 +1117 +1118 +1119 +1120 +1121 +1122 +1123 +1124 +1125 +1126 +1127 +1128 +1129 +1130 +1131 +1132 |
|
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
+ + +starlette_admin.views.DropDown
+
+
+
+ Bases: BaseView
Group views inside a dropdown
+ +starlette_admin/views.py
starlette_admin.views.Link
+
+
+
+ Bases: BaseView
Add arbitrary hyperlinks to the menu
+ + +starlette_admin/views.py
starlette_admin.views.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
starlette_admin.views.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
+ |
+
+
+
+ Indicate if the primary key should be excluded from create and +edit. Default to True + |
+
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.
+eg: |
+
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 + |
+
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 + |
+
starlette_admin/views.py
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 +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 |
|
can_create(request)
+
+can_delete(request)
+
+can_edit(request)
+
+can_view_details(request)
+
+count(request, where=None)
+
+
+ abstractmethod
+ async
+
+
+Count items
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
where |
+
+ Union[Dict[str, Any], str, None]
+ |
+ + + | +
+ None
+ |
+
starlette_admin/views.py
create(request, data)
+
+
+ abstractmethod
+ async
+
+
+Create item
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
data |
+
+ Dict
+ |
+
+
+
+ Dict values contained converted form data + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
Any |
+ Any
+ |
+
+
+
+ Created Item + |
+
starlette_admin/views.py
delete(request, pks)
+
+
+ abstractmethod
+ async
+
+
+Bulk delete items
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
pks |
+
+ List[Any]
+ |
+
+
+
+ List of primary keys + |
+ + required + | +
starlette_admin/views.py
edit(request, pk, data)
+
+
+ abstractmethod
+ async
+
+
+Edit item
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
pk |
+
+ Any
+ |
+
+
+
+ Primary key + |
+ + required + | +
data |
+
+ Dict[str, Any]
+ |
+
+
+
+ Dict values contained converted form data + |
+ + required + | +
Returns:
+Name | Type | +Description | +
---|---|---|
Any |
+ 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:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
where |
+
+ Union[Dict[str, Any], str, None]
+ |
+ + + | +
+ None
+ |
+
skip |
+
+ int
+ |
+
+
+
+ should return values start from position skip+1 + |
+
+ 0
+ |
+
limit |
+
+ int
+ |
+
+
+
+ number of maximum items to return + |
+
+ 100
+ |
+
order_by |
+
+ Optional[List[str]]
+ |
+
+
+
+ order data clauses in form |
+
+ None
+ |
+
starlette_admin/views.py
find_by_pk(request, pk)
+
+
+ abstractmethod
+ async
+
+
+Find one item
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
pk |
+
+ Any
+ |
+
+
+
+ Primary key + |
+ + required + | +
find_by_pks(request, pks)
+
+
+ abstractmethod
+ async
+
+
+Find many items
+ + + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
request |
+
+ Request
+ |
+
+
+
+ The request being processed + |
+ + required + | +
pks |
+
+ List[Any]
+ |
+
+
+
+ List of Primary key + |
+ + required + | +
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
handle_action(request, pks, name)
+
+
+ async
+
+
+Handle action with name
.
Raises:
+Type | +Description | +
---|---|
+ 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
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
{"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var _a=/["'&<>]/;Pn.exports=Aa;function Aa(e){var t=""+e,r=_a.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i