Exemple #1
0
class MoreActicl(object):
    list_display = ['title', 'body', 'auth']

    readonly_fields = ['detail']  # 只读字段

    exclude = ['auth']  # 不显示某个字段

    form_layout = (
        Fieldset(
            u'',
            Row('title', 'auth'),  # Row表示将里面的字段作为一行显示
            Row('classify'),
            css_class='unsort'  # 不让区块拖动
        ),
        Fieldset(
            ('正文内容'),  # Fieldset第一个参数表示区块名称
            'body',
        ),
        Fieldset(
            ('备注'),
            Row('detail'),
            css_class='unsort no_title'  # no_title是不显示区块的title名称
        ),
        TabHolder(
            Tab(
                'body-raw',
                Field('title',
                      css_class="extra"),  # css_class="extra"可以将输入框占一整行
                Field('body'),
                css_class='unsort'),
            Tab('body-json', Field('body', )),
            css_class='unsort',
        ))
Exemple #2
0
class ControlActicl(object):
    list_display = ['title', 'body', 'auth']

    # readonly_fields = ['detail'] #设置只读字段

    # exclude = ['auth']  # 不显示某个字段
    # 传入元组
    form_layout = (
        Fieldset(('基本信息'),
                 Row('title', 'auth'),  # Row表示将里面的字段显示为一行
                 Row('classify'),
                 css_class='unsort',  # 不让区块移动
                 ),
        Fieldset(('正文内容'),  # Fieldset第一个参数表示区块名称
                 'body',
                 css_class='unsort',
                 ),
        Fieldset(('备注'),
                 Row('detail'),
                 css_class='unsort no_title',  # no_title是不显示区块的名称
                 ),
        TabHolder(
            Tab('body-row',
                Field('title', css_class='extra'),
                Field('body'),
                css_class='unsort'
                ),
            Tab('body-json',
                Field('body', ),
                ),
            css_class='unsort',
        )
    )
Exemple #3
0
class ControlActicl(object):
    list_display = ['title', 'body', 'auth']

    #readonly_fields = ['detail']  # 只读字段

    #exclude = ['auth']  # 不显示某个字段

    form_layout = [
        Fieldset('主要信息',
                 Row('title', 'auth'),
                 Row('classify'),
                 css_class='unsort'),
        Fieldset(
            ('正文内容'),  # Fieldset第一个参数表示区块名称
            'body',
            css_class='unsort'),
        Fieldset(
            ('备注'),
            Row('detail'),
            css_class='unsort no_title'  # no_title是不显示区块的title名称
        ),
        TabHolder(
            Tab('body-raw',
                Field('title', css_class="extra"),
                Field('body'),
                css_class='unsort'),
            Tab('body-json', Field('body', )),
            css_class='unsort',
        )
    ]
Exemple #4
0
class CourseAdmin(object):
    list_display = ['name','time','type','level','introduction','studey_num','create_time','update_time','section','teacher']
    search_fileds = ['name','time','type','level']
    list_filter = ['name','time','type','level']

    #dj39
    form_layout = (
        Fieldset(u'',
             Row('name','time','type'),
             Row('level','studey_num','teacher'),
             #模块不可以拖动
             css_class='unsort'
         ),
        Fieldset(('描述'),
             Row('introduction'),
        ),
        Fieldset(('章节'),
             Row('section'),
             #不显示区块的title名
             css_class='unsort no_title'
        ),
        #dj41
        TabHolder(
            Tab('标签1',
                Field('name',css_class="extra"),#输入框可以占一整行
                Field('time'),
                css_class='unsort'),
            Tab('标签2',
                Field('type','level'),
                Field('teacher'),
                )
        ),
    )
Exemple #5
0
class HostAdmin(object):
    def open_web(self, instance):
        return "<a href='http://%s' target='_blank'>Open</a>" % instance.ip
    open_web.short_description = "Acts"
    open_web.allow_tags = True
    open_web.is_column = True

    list_display = ('name', 'idc', 'guarantee_date', 'service_type',
                    'status', 'open_web', 'description')
    list_display_links = ('name',)

    raw_id_fields = ('idc',)
    style_fields = {'system': "radio-inline"}

    search_fields = ['name', 'ip', 'description']
    list_filter = ['idc', 'guarantee_date', 'status', 'brand', 'model',
                   'cpu', 'core_num', 'hard_disk', 'memory', 'service_type']

    list_bookmarks = [{'title': "Need Guarantee", 'query': {'status__exact': 2}, 'order': ('-guarantee_date',), 'cols': ('brand', 'guarantee_date', 'service_type')}]

    show_detail_fields = ('idc',)
    list_editable = (
        'name', 'idc', 'guarantee_date', 'service_type', 'description')
    save_as = True

    aggregate_fields = {"guarantee_date": "min"}

    form_layout = (
        Main(
            TabHolder(
                Tab('Comm Fiels',
                    Fieldset('Company data',
                             'name', 'idc',
                             description="some comm fields, required"
                             ),
                    Inline(MaintainLog),
                    ),
                Tab('Extend Fiedls',
                    Fieldset('Contact details',
                             'service_type',
                             Row('brand', 'model'),
                             Row('cpu', 'core_num'),
                             Row(AppendedText(
                                 'hard_disk', 'G'), AppendedText('memory', "G")),
                             'guarantee_date'
                             ),
                    ),
            ),
        ),
        Side(
            Fieldset('Status data',
                     'status', 'ssh_port', 'ip'
                     ),
        )
    )
    inlines = [MaintainInline]
    reversion_enable = True
Exemple #6
0
class ScanTaskAdmin(object):
    def queryset(self):
        qs = super(ScanTaskAdmin, self).queryset()
        if self.request.user.username in PREVILEGED_USER_SETS:
            return qs
        else:
            return qs.filter(workspace__user=self.request.user)

    list_display = (
        'targets',
        "ports",
        "imports_active",
        "scan_scheme",
        "date_created",
    )
    # list_display = ('targets', "ports", "scan_scheme", "date_created", schedule)
    list_editable = ['imports_active', 'workspace']

    fieldsets = [
        # ("基本描述", {'fields': ['type', "name", "desc"] }),
        ('工作组', {
            'fields': ['workspace']
        }),
        ('文件导入', {
            'fields': ['imports_active', 'imports']
        }),
        ('自定义目标', {
            'fields': ['targets', "ports", "udp", "domains"]
        }),
        ('选定扫描方案', {
            'fields': ['scan_scheme']
        }),
        ('执行类型', {
            'fields': ['atnow', "regular", "interval", "crontab"]
        }),
    ]

    # wizard_form_list = fieldsets

    # inlines = [WorkspaceInline, ]

    form_layout = (Main(
        TabHolder(
            Tab(
                "文件添加扫描",
                Fieldset(
                    "基础扫描设置",
                    "workspace",
                    "scan_scheme",
                    Row("imports_active", "imports"),
                    Row("atnow", "regular"),
                ),
            ), ), ),
                   Side(
                       Fieldset("自定义目标", 'targets', "ports", "udp",
                                "domains"), ))
Exemple #7
0
class PorteurAdmin(object):

    list_display = ('nom', 'prenom', 'statut')
    search_fields = ('nom', )
    list_filter = ('statut', )
    model_icon = 'fa fa-user'

    inlines = (SouscriptionSvcInLine, )

    form_layout = (TabHolder(
        Tab(
            'Général',
            Fieldset('Généralités', 'nom', 'prenom', 'date_de_naissance',
                     'statut'),
            Inline(SouscriptionSvc),
        ), ), )
Exemple #8
0
class MemberAdmin(object):

    def show_avatar(self, event):
        return event.avatar and '<img src="%s" height="30"/>' % event.avatar.url or ''
    show_avatar.short_description = "头像"
    show_avatar.allow_tags = True

    list_display = ('number', 'show_avatar', 'username', 'email', 'qq', 'gender', 'title')
    list_filter = ('username', 'email', 'qq', 'gender', 'classnum', 'mobile', 'birthday')

    search_fields = ('number', 'username', 'email')

    ordering = ('number',)
    style_fields = {'user_permissions': 'm2m_transfer', 'departments': 'm2m_tree', 'gender': 'radio-inline'}
    model_icon = 'fa fa-user'
    relfield_style = 'fk-ajax'

    exclude = ('last_login',)

    form_layout = (
        TabHolder(
            Tab('必填项目',
                Fieldset('个人信息',
                    'number', 'username', 'avatar', 'classnum', 'birthday', 'gender', 'departments', 'is_active',
                    description="个人注册所需信息"
                ),
                Fieldset('联系方式',
                    'email', 'qq', 'mobile', 'weixin',
                    description="务必仔细填写您的联系方式,以便接受通知"
                ),
                css_id='comm'
            ),
            Tab('权限分配',
                'password',
                'groups', 'user_permissions',
                'is_superuser',
                css_id='permission'
            ),
            Tab('选填项目',
                'title', 'industry', 'position',
                'is_party', 'is_direct', 'is_move_hukou',
                'note',
                css_id='option'
            ),
        ),
    )
Exemple #9
0
class HostAdmin(object):
    def open_web(self, instance):
        return """<a href="http://%s" target="_blank">Open</a>""" % instance.ip

    open_web.short_description = "Acts"
    open_web.allow_tags = True
    open_web.is_column = True

    list_display = (
        "name",
        "idc",
        "guarantee_date",
        "service_type",
        "status",
        "open_web",
        "description",
        "ip",
    )
    list_display_links = ("name", )

    raw_id_fields = ("idc", )
    style_fields = {"system": "radio-inline"}

    search_fields = ["name", "ip", "description", "idc__name"]
    list_filter = [
        "idc",
        "guarantee_date",
        "status",
        "brand",
        "model",
        "cpu",
        "core_num",
        "hard_disk",
        "memory",
        (
            "service_type",
            xadmin.filters.MultiSelectFieldListFilter,
        ),
    ]

    list_quick_filter = ["service_type", {"field": "idc__name", "limit": 10}]
    # list_quick_filter = ["idc_id"]
    list_bookmarks = [{
        "title": "Need Guarantee",
        "query": {
            "status__exact": 2
        },
        "order": ("-guarantee_date", ),
        "cols": ("brand", "guarantee_date", "service_type"),
    }]

    show_detail_fields = ("idc", )
    list_editable = ("name", "idc", "guarantee_date", "service_type",
                     "description", "ip")
    save_as = True

    aggregate_fields = {"guarantee_date": "min"}
    grid_layouts = ("table", "thumbnails")

    form_layout = (Main(
        TabHolder(
            Tab(
                "Comm Fields",
                Fieldset(
                    "Company data",
                    "name",
                    "idc",
                    description="some comm fields, required",
                ),
                Inline(MaintainLog),
            ),
            Tab(
                "Extend Fields",
                Fieldset(
                    "Contact details", "service_type", Row("brand", "model"),
                    Row("cpu", "core_num"),
                    Row(AppendedText("hard_disk", "G"),
                        AppendedText("memory", "G")), "guarantee_date"),
            ),
        ), ), Side(Fieldset("Status data", "status", "ssh_port", "ip"), ))
    inlines = [MaintainInline]
    reversion_enable = True

    data_charts = {
        "host_service_type_counts": {
            'title': u"Host service type count",
            "x-field": "service_type",
            "y-field": ("service_type", ),
            "option": {
                "series": {
                    "bars": {
                        "align": "center",
                        "barWidth": 0.8,
                        'show': True
                    }
                },
                "xaxis": {
                    "aggregate": "count",
                    "mode": "categories"
                },
            },
        },
    }
Exemple #10
0
class HostAdmin(object):
    def open_web(self, instance):
        return "<a href='http://%s' target='_blank'>Open</a>" % instance.ip

    open_web.short_description = "Acts"
    open_web.allow_tags = True
    open_web.is_column = True

    list_display = ('name', 'idc', 'guarantee_date', 'service_type', 'status',
                    'open_web', 'description')
    list_display_links = ('name', )

    raw_id_fields = ('idc', )
    style_fields = {'system': "radio-inline"}

    search_fields = ['name', 'ip', 'description']
    list_filter = [
        'idc', 'guarantee_date', 'status', 'brand', 'model', 'cpu', 'core_num',
        'hard_disk', 'memory',
        ('service_type', xadmin.filters.MultiSelectFieldListFilter)
    ]

    list_quick_filter = ['service_type', {'field': 'idc__name', 'limit': 10}]
    list_bookmarks = [{
        'title': "Need Guarantee",
        'query': {
            'status__exact': 2
        },
        'order': ('-guarantee_date', ),
        'cols': ('brand', 'guarantee_date', 'service_type')
    }]

    show_detail_fields = ('idc', )
    list_editable = ('name', 'idc', 'guarantee_date', 'service_type',
                     'description')
    save_as = True

    aggregate_fields = {"guarantee_date": "min"}
    grid_layouts = ('table', 'thumbnails')

    form_layout = (Main(
        TabHolder(
            Tab(
                'Comm Fields',
                Fieldset('Company data',
                         'name',
                         'idc',
                         description="some comm fields, required"),
                Inline(MaintainLog),
            ),
            Tab(
                'Extend Fields',
                Fieldset(
                    'Contact details', 'service_type', Row('brand', 'model'),
                    Row('cpu', 'core_num'),
                    Row(AppendedText('hard_disk', 'G'),
                        AppendedText('memory', "G")), 'guarantee_date'),
            ),
        ), ), Side(Fieldset('Status data', 'status', 'ssh_port', 'ip'), ))
    inlines = [MaintainInline]
    reversion_enable = True

    data_charts = {
        "host_service_type_counts": {
            'title': u"Host service type count",
            "x-field": "service_type",
            "y-field": ("service_type", ),
            "option": {
                "series": {
                    "bars": {
                        "align": "center",
                        "barWidth": 0.8,
                        'show': True
                    }
                },
                "xaxis": {
                    "aggregate": "count",
                    "mode": "categories"
                },
            },
        },
    }
Exemple #11
0
class WorkspaceAdmin(object):
    def queryset(self):
        qs = super(WorkspaceAdmin, self).queryset()
        if self.request.user.username in PREVILEGED_USER_SETS:
            return qs
        else:
            return qs.filter(user=self.request.user)

    # readonly_fields = ('user', )
    def uniq_name(self, instance):
        return instance.name + "_" + instance.user.username

    uniq_name.short_description = "唯一ID"
    uniq_name.allow_tags = True
    uniq_name.is_column = True

    list_editable = ['name', 'summary']
    list_display = (
        'name',
        "user",
        'uniq_name',
        'summary',
        'date_updated',
    )

    fieldsets = [
        ("工作组名称", {
            'fields': ['name']
        }),
        ('用户', {
            'fields': ['user'],
            'classes': ['collapse']
        }),
    ]

    # form_layout = (
    #     Fieldset("名称", 'name', 'summary'),
    #     Fieldset(None, 'user', 'desc', 'id', **{"style": "display:None"}),
    # )

    inlines = [
        ScanTaskInline,
    ]

    actions = None
    # aggregate_fields = {"user_count": "sum", "view_count": "sum"}
    # refresh_times = (3, 5, 10)

    form_layout = (Main(TabHolder(Tab(
        "创建扫描任务",
        'name',
        Inline(ScanTask),
    ), ), ),
                   Side(
                       Fieldset("名称", 'summary'),
                       Fieldset(None, 'user', 'desc', 'id',
                                **{"style": "display:None"}),
                   ))

    def save_models(self):
        instance = self.new_obj
        request = self.request

        instance.user = request.user
        instance.save()
Exemple #12
0
class ProductAdmin(object):

    list_display = ['productName', 'image', 'sellerSku', 'brand', 'status']
    list_display_links = ['productName']

    list_filter = ('brand', 'series', 'status')

    search_fields = ('productName', 'sellerSku')
    show_detail_fields = ['productName']

    style_fields = {"accessories": "checkbox-inline"}

    form_layout = (
        Main(
            TabHolder(
                Tab(
                    "Product Inf",
                    Fieldset(
                        "Basic Inf",
                        "productName",
                        'title',
                        "status",
                        'sellerSku',
                        'image',
                        # Row(
                        #     AppendedText("weight", "G"),
                        #     AppendedText("offer", "$")
                        # ),
                        AppendedText("weight", "G"),
                        AppendedText("offer", "$"),
                        'brand',
                        'series',
                        'number',
                        'target_audience',
                        'scene',
                        'designer',
                        'inf_more',
                        'slogan',
                        'features',
                        'a_description',

                        # description="产品的一些基本信息",
                    )),
                Tab(
                    "More Inf",
                    Fieldset(
                        "More Inf",
                        'accessories',
                    ),
                )), ),
        # Side(
        #     Fieldset("什么都没有"),
        # )
    )
    #设置导出的列
    list_export_fields = ("productName", 'title', "status", 'sellerSku')
    list_per_page = 15
    import_export_args = {
        'import_resource_class': PustomerResource,
        # 'export_resource_class': ProductInfoResource,
    }
Exemple #13
0
class IDCAdmin(object):

    # 自定义显示列
    def open_web(self, instance):
        return """<a href="http://%s" target="_blank">Open</a>""" % instance.name

    open_web.short_description = "Acts"
    open_web.allow_tags = True
    open_web.is_column = True

    # 插件 list
    # 列表显示的字段 默认 ('__str__',)
    list_display = ('name', 'description', 'create_time', 'contact', 'telphone', 'address', 'customer_id', 'open_web')
    # 显示修改或查看数据详情连接的列
    list_display_links = ('name',)
    # 点击列表连接后是否转到详情页面
    list_display_links_details = False
    # 是否提前加载关联数据, 使用 ``select_related``
    list_select_related = None
    # 每页显示数据的条数
    list_per_page = 50
    # 每页最大显示数据的条数
    list_max_show_all = 200
    # 排除显示的列, 在显示列的设置中不会出现这些被排除的列
    list_exclude = ()
    # 搜索的字段, 使用模糊搜索
    search_fields = ['name', 'description', 'contact', 'telphone', 'address']
    # 是否可以自由搜索. 如果开启自由搜索, 用户可以通过 url 参数来进行特定的搜索, 例如:name__contains=我,默认为 True
    # 这个会影响到过滤,因为他也规范化了过滤查询内容
    # free_query_filter = False
    # 排序(加‘-’表示降序)
    # ordering = None

    # 添加数据时候,一步一步填写数据
    wizard_form_list = [
        ('第一步', ('name', 'description')),
        ('第二步', ('contact', 'telphone', 'address')),
        ('第三步', ('customer_id',))
    ]

    # 过滤器, 系统会自动生成搜索器
    list_filter = ['name', ]
    # list_quick_filter 必须是 list_filter 的一个子集才能工作
    list_quick_filter = [{'field': 'name', 'limit': 10}]
    # 添加过滤(这里是过滤日期)
    # date_hierarchy = ['date']
    # filter_horizontal 从‘多选框’的形式改变为‘过滤器’的方式,水平排列过滤器,
    # 必须是一个 ManyToManyField类型,且不能用于 ForeignKey字段,
    # 默认地,管理工具使用``下拉框`` 来展现`` 外键`` 字段
    # filter_horizontal = ('authors',)
    # 同上 filter_horizontal,垂直排列过滤器
    # filter_vertical = ['authors', ]

    # 开启书签功能,默认为 True
    # show_bookmarks = False
    # 设置默认书签
    # 用户可以在列表页面添加自己的书签, 我们可以设定好一些默认书签
    list_bookmarks = [{
        'title': '我是默认书签',  # 书签的名称, 显示在书签菜单中
        'query': {'name__exact': '123'},  # 过滤参数, 是标准的 queryset 过滤
        'order': ('-name',),  # 排序参数
        'cols': ('name', 'contact'),  # 显示的列
        'search': 'name'  # 搜索参数, 指定搜索的内容
    },
    ]

    # 定义数据导出功能,可以导出 Excel, CSV, XML, json 格式('xls', 'csv', 'xml', 'json')
    list_export = ('xls', 'csv', 'xml', 'json')

    # 列表定时刷新
    # 定义自动刷新列表, 用户可以选择3秒或5秒刷新一次页面
    refresh_times = (3, 5)

    # 显示数据详情 details
    # 设置哪些字段要显示详细信息的按钮
    show_detail_fields = ['name', ]
    # 自动显示所有关联字段的详细信息, 该属性默认为 True
    # show_all_rel_details = False

    # 数据即时编辑
    # 使用 Ajax , 无需提交或刷新页面即可完成数据的修改
    list_editable = ['name']

    # 将ForeignKey字段从‘下拉框’改变为‘文本框’显示
    raw_id_fields = ("groups",)

    # 当 Model 是其他 Model 的 ref model 时,其他 Model 在显示本 Model 的字段时使用的 Field Style
    # fk-ajax 涉及到外键下拉的时候使用ajax搜索的方式而不是全部列出的方式,比如在分类下拉很多的情况下,这个功能就很好用
    relfield_style = 'fk-select'

    # 图标样式
    model_icon = 'fa fa-user-secret'

    reversion_enable = True

    # 插件 edit
    # 是否显示 ``另存为`` 按钮,默认为 False
    save_as = True
    # 是否在页面上面显示按钮组,默认为 False,这个测试无效
    # save_on_top = True
    # 字段显示样式
    # style_fields = {
    #     "name": "radio-inline",
    #     "contact": "checkbox-inline",
    # }

    # 页面 Form 的 Layout 对象,是一个标准的 Crispy Form Layout 对象。
    # 使用 Layout 可以方便的定义整个 Form 页面的结构。
    form_layout = (
        # 主区域
        Main(
            TabHolder(
                Tab(
                    'TAB 名字',
                    Fieldset(
                        '名字',
                        # 单行显示字段内容
                        Row('telphone', 'address'),
                        'description',
                        # Inline(MaintainLog),  # 无效
                        description='一些说明文字',
                    ),
                ),
                Tab(
                    'TAB 名字 2',
                    Fieldset(
                        '一些名字',
                        Row('telphone', 'address'),
                        Row(
                            AppendedText('customer_id', '描述'),
                        ),
                        # 'create_time'    # 无效
                    ),
                ),
            ),
        ),
        # 侧边区域
        Side(
            Fieldset('Status data', 'telphone', 'address'),
        )
    )

    # 插件 aggregation
    # 列聚合,在list表格下面会增加一行统计的数据,可用的值: count min max avg sum
    # aggregate_fields = {'user_count': 'sum', }

    # 插件 layout
    # 列表的布局方式,是以表格一行一条的方式还是类似于缩略图的方式展示的
    # grid_layouts = ("table", "thumbnails")

    # actions 属性是一个列表, 包含启用的 Action 的类. 系统已经默认内置了删除数据的 Action,
    # 可以制作 Action 来实现特定的功能, 例如 MyAction
    actions = [BatchChangeAction, MyAction, ]
    # 批处理的字段
    batch_fields = ('contact', 'description', 'address', 'customer_id')
Exemple #14
0
class ChargingPileAdmin(object):
    """
    充电桩管理
    """
    list_display = ['name', 'pile_sn', 'pile_type', 'station', 'pile_mode', 'business_mode',
                    'get_work_status']
    list_display_links = ('name',)
    search_fields = ['pile_sn', 'name', 'pile_type', 'station']
    exclude = ["qrcode", 'group']
    list_filter = ['pile_type', 'station', 'pile_mode', 'business_mode']
    readonly_fields = ['user']

    model_icon = 'fa fa-sitemap'
    show_all_rel_details = False
    # list_editable = ['pile_type', 'pile_sn']
    refresh_times = [3, 5]  # 计时刷新
    save_as = True
    style_fields = {
        "low_restrict": "radio-inline", "low_offset": "radio-inline",
        "subscribe_status": "radio-inline",
        "occupy_status": "radio-inline",
        'sub_status': "radio-inline",
        'charg_mode': "radio-inline",
    }

    form_layout = (
        Main(
            TabHolder(
                Tab(
                    '基础信息设置',
                    Fieldset(
                        '基础信息',
                        Row('name', 'pile_type'),
                        Row('pile_sn', 'power'),
                        Row('station', 'pile_mode'),
                        Row('business_mode', 'fireware'),
                        Row('symbol_4g', 'symbol_eth'),
                        'charg_mode',
                        'sub_time',
                        Row('is_subsidy', 'faults'),
                    ),
                    Inline(ChargingGun),
                    css_id="base_info",
                ),
                Tab(
                    '其他设置',
                    Fieldset(
                        "预约及占位设置",
                        'charg_policy',
                        Row('subscribe_status', AppendedText('subscribe_fee', '元')),
                        Row('occupy_status', AppendedText('occupy_fee', '元')),
                    ),
                    Fieldset(
                        "小电流设置参数",
                        Row('low_restrict', AppendedText('low_cur_value', '毫安')),
                        Row('low_offset', AppendedText('low_offset_value', '元')),
                    ),
                    Fieldset(
                        "单枪参数",
                        Row(AppendedText('gun_max_voltage', '伏'), AppendedText('gun_min_voltage', '伏')),
                        Row(AppendedText('gun_max_current', '安'), AppendedText('gun_min_current', '安')),
                    ),
                    css_id="other_set",
                ),
            ),
        ),
        Side(
            Fieldset("其他信息", 'sub_status',  'user', 'max_gun', 'restart_nums'),
        )
    )

    inlines = [ChargingGunInline]

    def queryset(self):
        queryset = super(ChargingPileAdmin, self).queryset()
        if self.request.user.station:
            return queryset.filter(station=self.request.user.station)
        elif self.request.user.seller:
            return queryset.filter(station__seller=self.request.user.seller)
        else:
            return queryset

    def formfield_for_dbfield(self, db_field,  **kwargs):
        if db_field.name == 'station':
            if not self.request.user.is_superuser:
                kwargs['queryset'] = Station.objects.filter(seller=self.request.user.seller)
        return super(ChargingPileAdmin, self).formfield_for_dbfield(db_field,  **kwargs)

    def save_models(self):
        obj = self.new_obj
        request = self.request
        obj.user = request.user
        obj.group = request.user.groups.first()

        super(ChargingPileAdmin, self).save_models()

    def save_related(self):
        obj = self.new_obj
        super(ChargingPileAdmin, self).save_related()
        for inst in obj.charginggun_set.all():
            self.save_image(inst)

    def save_image(self, instance):
        upload_path = instance.qrcode.field.upload_to
        dirs = os.path.join(settings.MEDIA_ROOT, upload_path)
        if not os.path.exists(dirs):
            os.makedirs(dirs)

        domain_url = settings.ROOT_URL if settings.ROOT_URL else "http://" + self.request.get_host()
        # domain_url = "http://" + self.request.get_host()
        path = reverse('order-prepay', kwargs={'pile_sn': instance.charg_pile.pile_sn, "gun_num": instance.gun_num})
        qrcode_content = '{0}{1}'.format(domain_url, path)
        image = create_qrcode(qrcode_content)
        image_url = '{0}_{1}.png'.format(instance.charg_pile.pile_sn, instance.gun_num)
        image.save(os.path.join(dirs, image_url), quality=100)
        instance.qrcode = '{0}{1}'.format(upload_path, image_url)
        instance.save()

    def station_choices(self, field, request, params, model, model_admin, field_path):
        if self.request.user.station:
            stations = Station.objects.filter(id=self.request.user.station.id).values("id", "name")
        elif self.request.user.seller:
            stations = Station.objects.filter(seller_id=self.request.user.seller.id).values("id", "name")
        else:
            return field.get_choices(include_blank=False)

        return list(((station.get('id'), station.get('name')) for station in stations))