django管理列表显示从多个到多个的排序

时间:2016-02-08 12:33:55

标签: python django django-admin

请帮我解决一个问题我尝试了很多,但遗憾的是找不到解决方案

我的代码在

models.py

    class MeasuredController(MeasuredObject):
        .....
        tempraturemeasure = models.ManyToManyField(MeasuredTemperature, blank=True, null=True)
        .....


    class MeasuredTemperature(MeasuredObject):
        ......
        temperature = models.DecimalField(max_digits=6,decimal_places=1,verbose_name='Temperature[C]')         .....

admin.py

    class MeasuredControllerAdmin( admin.ModelAdmin):
        list_display = ('tem0', 'tem1', 'tem2')

        def tem2(self, obj): 
            ...............   
            return obj.tempraturemeasure.filter(deviceindex="2").latest("senddate").temperature
            .......

        def tem1(self, obj): 
            ...............   
            return obj.tempraturemeasure.filter(deviceindex="1").latest("senddate").temperature
            .......

        def tem0(self, obj): 
            ...............   
            return obj.tempraturemeasure.filter(deviceindex="0").latest("senddate").temperature
            .......

我的问题是否可以对admin中的tem0tem1tem2列进行排序

1 个答案:

答案 0 :(得分:0)

您可以通过创建子查询来完成此操作,请尝试这样

request.getParameter("")