Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_45031851
simpleui_demo
提交
94bb671b
S
simpleui_demo
项目概览
weixin_45031851
/
simpleui_demo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
simpleui_demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
94bb671b
编写于
12月 02, 2020
作者:
J
Jingle
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加新功能 layer dialog
上级
f1f83a91
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
195 addition
and
5 deletion
+195
-5
db.sqlite3
db.sqlite3
+0
-0
demo/admin.py
demo/admin.py
+54
-3
finance/admin.py
finance/admin.py
+141
-2
未找到文件。
db.sqlite3
浏览文件 @
94bb671b
无法预览此类型文件
demo/admin.py
浏览文件 @
94bb671b
...
...
@@ -2,8 +2,10 @@ import datetime
from
django.contrib
import
admin
,
messages
from
django.db
import
transaction
from
django.http
import
JsonResponse
from
django.urls
import
reverse
from
simpleui.admin
import
AjaxAdmin
from
.models
import
*
from
import_export
import
resources
from
import_export.admin
import
ImportExportModelAdmin
,
ImportExportActionModelAdmin
...
...
@@ -77,7 +79,7 @@ class ProxyResource(resources.ModelResource):
@
admin
.
register
(
Employe
)
class
EmployeAdmin
(
ImportExportActionModelAdmin
):
class
EmployeAdmin
(
ImportExportActionModelAdmin
,
AjaxAdmin
):
resource_class
=
ProxyResource
list_display
=
(
'id'
,
'name'
,
'gender'
,
'phone'
,
'birthday'
,
'department'
,
'enable'
,
'create_time'
)
# search_fields = ('name', 'enable', 'idCard', 'department')
...
...
@@ -97,7 +99,7 @@ class EmployeAdmin(ImportExportActionModelAdmin):
(
u
'其他信息'
,
{
'classes'
:
(
'123'
,),
'fields'
:
[
'birthday'
,
'department'
,
'enable'
]})]
save_on_top
=
True
@
transaction
.
atomic
def
test
(
self
,
request
,
queryset
):
messages
.
add_message
(
request
,
messages
.
SUCCESS
,
'啥也没有~'
)
...
...
@@ -107,7 +109,56 @@ class EmployeAdmin(ImportExportActionModelAdmin):
test
.
confirm
=
'您确定要点击测试按钮吗?'
# 增加自定义按钮
actions
=
[
test
,
'make_copy'
,
'custom_button'
]
actions
=
[
test
,
'make_copy'
,
'custom_button'
,
'layer_input'
]
def
layer_input
(
self
,
request
,
queryset
):
# 这里的queryset 会有数据过滤,只包含选中的数据
post
=
request
.
POST
# 这里获取到数据后,可以做些业务处理
# post中的_action 是方法名
# post中 _selected 是选中的数据,逗号分割
return
JsonResponse
(
data
=
{
'status'
:
'success'
,
'msg'
:
'处理成功!'
})
layer_input
.
short_description
=
'弹出对话框输入'
layer_input
.
type
=
'success'
layer_input
.
icon
=
'el-icon-s-promotion'
# 指定一个输入参数,应该是一个数组
# 指定为弹出层,这个参数最关键
layer_input
.
layer
=
{
# 弹出层中的输入框配置
# 这里指定对话框的标题
'title'
:
'弹出层输入框'
,
# 提示信息
'tips'
:
'这个弹出对话框是需要在admin中进行定义,数据新增编辑等功能,需要自己来实现。'
,
# 确认按钮显示文本
'confirm_button'
:
'确认提交'
,
# 取消按钮显示文本
'cancel_button'
:
'取消'
,
# 弹出层对话框的宽度,默认50%
'width'
:
'40%'
,
# 表单中 label的宽度,对应element-ui的 label-width,默认80px
'labelWidth'
:
"80px"
,
'params'
:
[{
# 这里的type 对应el-input的原生input属性,默认为input
'type'
:
'input'
,
# key 对应post参数中的key
'key'
:
'name'
,
# 显示的文本
'label'
:
'名称'
,
# 为空校验,默认为False
'require'
:
True
}]
}
def
custom_button
(
self
,
request
,
queryset
):
pass
...
...
finance/admin.py
浏览文件 @
94bb671b
from
django.contrib
import
admin
from
django.http
import
JsonResponse
from
finance.models
import
*
from
import_export
import
resources
from
import_export.admin
import
ImportExportModelAdmin
,
ImportExportActionModelAdmin
from
simpleui.admin
import
AjaxAdmin
class
ProxyResource
(
resources
.
ModelResource
):
class
Meta
:
...
...
@@ -14,9 +18,144 @@ class ProxyResource(resources.ModelResource):
@
admin
.
register
(
Record
)
# class RecordAdmin(admin.ModelAdmin):
# class RecordAdmin(ImportExportModelAdmin):
class
RecordAdmin
(
ImportExportActionModelAdmin
):
class
RecordAdmin
(
ImportExportActionModelAdmin
,
AjaxAdmin
):
resource_class
=
ProxyResource
list_display
=
(
'id'
,
'name'
,
'type'
,
'money'
,
'create_date'
)
list_per_page
=
10
actions
=
(
'layer_input'
,)
def
layer_input
(
self
,
request
,
queryset
):
# 这里的queryset 会有数据过滤,只包含选中的数据
post
=
request
.
POST
# 这里获取到数据后,可以做些业务处理
# post中的_action 是方法名
# post中 _selected 是选中的数据,逗号分割
if
not
post
.
get
(
'_selected'
):
return
JsonResponse
(
data
=
{
'status'
:
'error'
,
'msg'
:
'请先选中数据!'
})
else
:
return
JsonResponse
(
data
=
{
'status'
:
'success'
,
'msg'
:
'处理成功!'
})
layer_input
.
short_description
=
'弹出对话框输入'
layer_input
.
type
=
'success'
layer_input
.
icon
=
'el-icon-s-promotion'
# 指定一个输入参数,应该是一个数组
# 指定为弹出层,这个参数最关键
layer_input
.
layer
=
{
# 弹出层中的输入框配置
# 这里指定对话框的标题
'title'
:
'弹出层输入框'
,
# 提示信息
'tips'
:
'这个弹出对话框是需要在admin中进行定义,数据新增编辑等功能,需要自己来实现。'
,
# 确认按钮显示文本
'confirm_button'
:
'确认提交'
,
# 取消按钮显示文本
'cancel_button'
:
'取消'
,
# 弹出层对话框的宽度,默认50%
'width'
:
'40%'
,
# 表单中 label的宽度,对应element-ui的 label-width,默认80px
'labelWidth'
:
"80px"
,
'params'
:
[{
# 这里的type 对应el-input的原生input属性,默认为input
'type'
:
'input'
,
# key 对应post参数中的key
'key'
:
'name'
,
# 显示的文本
'label'
:
'名称'
,
# 为空校验,默认为False
'require'
:
True
},
{
'type'
:
'select'
,
'key'
:
'type'
,
'label'
:
'类型'
,
'width'
:
'200px'
,
# size对应elementui的size,取值为:medium / small / mini
'size'
:
'small'
,
# value字段可以指定默认值
'value'
:
'0'
,
'options'
:
[{
'key'
:
'0'
,
'label'
:
'收入'
},
{
'key'
:
'1'
,
'label'
:
'支出'
}]
},
{
'type'
:
'number'
,
'key'
:
'money'
,
'label'
:
'金额'
,
# 设置默认值
'value'
:
1000
},
{
'type'
:
'date'
,
'key'
:
'date'
,
'label'
:
'日期'
,
},
{
'type'
:
'datetime'
,
'key'
:
'datetime'
,
'label'
:
'时间'
,
},
{
'type'
:
'rate'
,
'key'
:
'star'
,
'label'
:
'评价等级'
},
{
'type'
:
'color'
,
'key'
:
'color'
,
'label'
:
'颜色'
},
{
'type'
:
'slider'
,
'key'
:
'slider'
,
'label'
:
'滑块'
},
{
'type'
:
'switch'
,
'key'
:
'switch'
,
'label'
:
'switch开关'
},
{
'type'
:
'input_number'
,
'key'
:
'input_number'
,
'label'
:
'input number'
},
{
'type'
:
'checkbox'
,
'key'
:
'checkbox'
,
# 必须指定默认值
'value'
:
[],
'label'
:
'复选框'
,
'options'
:
[{
'key'
:
'0'
,
'label'
:
'收入'
},
{
'key'
:
'1'
,
'label'
:
'支出'
},
{
'key'
:
'2'
,
'label'
:
'收益'
}]
},
{
'type'
:
'radio'
,
'key'
:
'radio'
,
'label'
:
'单选框'
,
'options'
:
[{
'key'
:
'0'
,
'label'
:
'收入'
},
{
'key'
:
'1'
,
'label'
:
'支出'
},
{
'key'
:
'2'
,
'label'
:
'收益'
}]
}]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录