2014-07-14 32 views
0

我使用Django的简单历史https://django-simple-history.readthedocs.org/en/latest/index.html管理我的网站的历史和Django的Ajax的选择https://github.com/crucialfelix/django-ajax-selects在我的web应用程序。我面临的问题是在管理员注册部分。最初,当我刚使用Django的Ajax-选择我的admin.py会像Django的:admin.site.register问题

class DeviceAdmin(AjaxSelectAdmin): 
    formfield_overrides = { 
    models.TextField: {'widget': Textarea(attrs={'rows': 6, 'cols': 50})}, 
} 
    list_display = ('__unicode__', 'Tag_ID', 'IMEI', 'Device_Name', 'Location', 'Employee_Name_Owner') 
    list_filter = ('Location__Location', 'Device_Name', 'Manufacturer__Manufacturer', 'Phone_Carrier__Phone_Carrier', 
       'Device_Type__Device_Type', 'Service_Status__Service_Status', 'Purchase_Date', 'Created_At', 
       'Updated_At') 
    search_fields = ('Tag_ID', 'IMEI', 'Phone_Number', 'MEID_HEX', 'MEID_DEC', 'Device_Name', 'Serial_Number', 
       'Employee_Name_Owner__Email') 
admin.site.register(Device,DeviceAdmin) 

但现在,当我尝试使用Django的sipmle历史根据其DOC我必须使用admin.site.register像

admin.site.register(Device, SimpleHistoryAdmin) 

最后因为admin.site.register使用SimpleHistoryAdmin我失去我DeviceAdmin类的所有功能。我需要一种方法来将DeviceAdminSimpleHistory Admin放在一起。

PS:道歉任何重复或问一个简单的问题。

回答

1

所以,你基本上想要你的管理页面Device扩展DeviceAdminSimpleHistoryAdmin所以你得到两个功能。

尝试以下操作:

class DeviceAdmin(AjaxSelectAdmin): 
    ... code that you have above ... 

class DeviceAdminWithHistory(DeviceAdmin, SimpleHistoryAdmin): 
    pass 

admin.site.register(Device, DeviceAdminWithHistory) 

有一个机会,这两个类DeviceAdminSimpleHistoryAdmin可能有重叠的字段或方法。但在看到SimpleHistoryAdminAjaxSelectAdmin的来源后,看起来上面应该可以工作。

+0

非常感谢。有效。一些我如何尝试相同的事情,但我想我是不正确地定义类。感谢你的帮助。 –