FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
fastapi-admin/examples/resources.py at dev · Medical-FastAPI/fastapi-admin · GitHub
Medical-FastAPI
fastapi-admin
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
fastapi-admin
/
examples
/
resources.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
165 lines (140 loc) · 4.51 KB
Breadcrumbs
fastapi-admin
/
examples
/
resources.py
Copy path
File metadata and controls
165 lines (140 loc) · 4.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
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
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
import
os
from
typing
import
List
from
starlette
.
requests
import
Request
from
examples
import
enums
from
examples
.
constants
import
BASE_DIR
from
examples
.
models
import
Admin
,
Category
,
Config
,
Product
from
fastapi_admin
.
app
import
app
from
fastapi_admin
.
enums
import
Method
from
fastapi_admin
.
file_upload
import
FileUpload
from
fastapi_admin
.
resources
import
Action
,
Dropdown
,
Field
,
Link
,
Model
,
ToolbarAction
from
fastapi_admin
.
widgets
import
displays
,
filters
,
inputs
upload
=
FileUpload
(
uploads_dir
=
os
.
path
.
join
(
BASE_DIR
,
"static"
,
"uploads"
))
@
app
.
register
class
Dashboard
(
Link
):
label
=
"Dashboard"
icon
=
"fas fa-home"
url
=
"/admin"
@
app
.
register
class
AdminResource
(
Model
):
label
=
"Admin"
model
=
Admin
icon
=
"fas fa-user"
page_pre_title
=
"admin list"
page_title
=
"admin model"
filters
=
[
filters
.
Search
(
name
=
"username"
,
label
=
"Name"
,
search_mode
=
"contains"
,
placeholder
=
"Search for username"
,
),
filters
.
Date
(
name
=
"created_at"
,
label
=
"CreatedAt"
),
]
fields
=
[
"id"
,
"username"
,
Field
(
name
=
"password"
,
label
=
"Password"
,
display
=
displays
.
InputOnly
(),
input_
=
inputs
.
Password
(),
),
Field
(
name
=
"email"
,
label
=
"Email"
,
input_
=
inputs
.
Email
()),
Field
(
name
=
"avatar"
,
label
=
"Avatar"
,
display
=
displays
.
Image
(
width
=
"40"
),
input_
=
inputs
.
Image
(
null
=
True
,
upload
=
upload
),
),
"created_at"
,
]
async
def
get_toolbar_actions
(
self
,
request
:
Request
)
->
List
[
ToolbarAction
]:
return
[]
async
def
cell_attributes
(
self
,
request
:
Request
,
obj
:
dict
,
field
:
Field
)
->
dict
:
if
field
.
name
==
"id"
:
return
{
"class"
:
"bg-danger text-white"
}
return
await
super
().
cell_attributes
(
request
,
obj
,
field
)
async
def
get_actions
(
self
,
request
:
Request
)
->
List
[
Action
]:
return
[]
async
def
get_bulk_actions
(
self
,
request
:
Request
)
->
List
[
Action
]:
return
[]
@
app
.
register
class
Content
(
Dropdown
):
class
CategoryResource
(
Model
):
label
=
"Category"
model
=
Category
fields
=
[
"id"
,
"name"
,
"slug"
,
"created_at"
]
class
ProductResource
(
Model
):
label
=
"Product"
model
=
Product
filters
=
[
filters
.
Enum
(
enum
=
enums
.
ProductType
,
name
=
"type"
,
label
=
"ProductType"
),
filters
.
Datetime
(
name
=
"created_at"
,
label
=
"CreatedAt"
),
]
fields
=
[
"id"
,
"name"
,
"view_num"
,
"sort"
,
"is_reviewed"
,
"type"
,
Field
(
name
=
"image"
,
label
=
"Image"
,
display
=
displays
.
Image
(
width
=
"40"
)),
Field
(
name
=
"body"
,
label
=
"Body"
,
input_
=
inputs
.
Editor
()),
"created_at"
,
]
label
=
"Content"
icon
=
"fas fa-bars"
resources
=
[
ProductResource
,
CategoryResource
]
@
app
.
register
class
ConfigResource
(
Model
):
label
=
"Config"
model
=
Config
icon
=
"fas fa-cogs"
filters
=
[
filters
.
Enum
(
enum
=
enums
.
Status
,
name
=
"status"
,
label
=
"Status"
),
filters
.
Search
(
name
=
"key"
,
label
=
"Key"
,
search_mode
=
"equal"
),
]
fields
=
[
"id"
,
"label"
,
"key"
,
"value"
,
Field
(
name
=
"status"
,
label
=
"Status"
,
input_
=
inputs
.
RadioEnum
(
enums
.
Status
,
default
=
enums
.
Status
.
on
),
),
]
async
def
row_attributes
(
self
,
request
:
Request
,
obj
:
dict
)
->
dict
:
if
obj
.
get
(
"status"
)
==
enums
.
Status
.
on
:
return
{
"class"
:
"bg-green text-white"
}
return
await
super
().
row_attributes
(
request
,
obj
)
async
def
get_actions
(
self
,
request
:
Request
)
->
List
[
Action
]:
actions
=
await
super
().
get_actions
(
request
)
switch_status
=
Action
(
label
=
"Switch Status"
,
icon
=
"ti ti-toggle-left"
,
name
=
"switch_status"
,
method
=
Method
.
PUT
,
)
actions
.
append
(
switch_status
)
return
actions
@
app
.
register
class
GithubLink
(
Link
):
label
=
"Github"
url
=
"https://github.com/fastapi-admin/fastapi-admin"
icon
=
"fab fa-github"
target
=
"_blank"
@
app
.
register
class
DocumentationLink
(
Link
):
label
=
"Documentation"
url
=
"https://fastapi-admin-docs.long2ice.io"
icon
=
"fas fa-file-code"
target
=
"_blank"
@
app
.
register
class
ProLink
(
Link
):
label
=
"Pro Version"
url
=
"https://fastapi-admin-pro.long2ice.io/admin/login"
icon
=
"far fa-heart"
target
=
"_blank"
Back
|
FazBrowse Home
|
New Git URL