class DeviceAdmin(AjaxSelectAdmin): form=make_ajax_form(Device,{'deviceID':'deviceID', 'deviceLocation':'deviceLocation',}) def get_deviceMain_state(self,obj): if obj.deviceMainStatus=='OK': return u'<span style="color:green;\font-weight:bold">%s</span>'%(u"状态良好",) elif obj.deviceMainStatus=='NEAR':return u'<span style="color:orange;\ font-weight:bold">%s</span>'%(u"即将过期",) else:return u'<span style="color:red;\ font-weight:bold">%s</span>'%(u"已过期",) get_deviceMain_state.short_description=u'维护状态' get_deviceMain_state.allow_tags=True date_hierarchy='deviceTime'list_filter=[LineFilter,StationFilter,DeviceMainStateFilter,'deviceStatus','deviceCate','deviceDesc', 'deviceModel','deviceTime','deviceCycle'] list_display=('deviceID','deviceCate','deviceDesc','deviceModel','deviceLine','deviceStation', 'deviceLocation','deviceStatus','deviceTime', 'deviceCycle','get_deviceMain_state',)#list search_fields=['deviceID','deviceCate__cateName','deviceDesc__descName','deviceModel__modelName', 'deviceLine__lineName','deviceStation__stationName', 'deviceLocation','deviceStatus','deviceTime', 'deviceCycle','deviceMainStatus'] fields=['deviceID','deviceCate','deviceDesc','deviceModel','deviceLine','deviceStation','deviceLocation', 'deviceStatus','deviceTime','deviceCycle','deviceMainStatus'] list_per_page=10 class Media:js=("/static/instantsearch.js",)
时间: 2023-12-27 20:02:42 浏览: 123
这段代码是一个 Django 的 admin 页面,用于管理一个名为 Device 的模型。其中,使用了一个名为 AjaxSelectAdmin 的类,可以实现在 admin 页面中使用 Ajax 实时搜索和选择相关模型的对象。另外,还定义了一个名为 get_deviceMain_state 的函数,用于显示设备的维护状态。整个 admin 页面还包括了一些过滤器、排序方式、每页显示数量等设置。最后,使用了一个名为 instantsearch.js 的 JavaScript 文件。
阅读全文