我在数数的时候好像有问题。我有一个列表项,其中每个项可以存储许多状态,尽管我只对它的最新状态感兴趣。现在看看我的观点。在
storage_items = StorageItem.objects\
.filter(client=client_id,itemstatushistory__isnull=False)\
.distinct()
total_items_in_stock = [item for item in storage_items \
if item.itemstatushistory_set.latest().status.description \
not in ['Destroyed','Permanent Retrieval']]
total_items_in_stock
显示所有没有最新状态的项,称为Destroyed
和Permanent Retrieval
。但这有一个问题。在
假设我的数据库中有一些项目-比如item1{in,out,destroyed},item2={destroyed,in},item3={permanently retrieve},item4={}。因为它查找最新状态,所以它将打印{item2}。我现在想在staock中打印item4。基本上item4是一个没有状态的项。但是由于它还没有Destroyed
或Permanent
检索,所以需要将其包含在列表中。但我似乎找不到一条出路。我希望我已经把一切都说清楚了。在
模板
^{pr2}$
另一种方法是将
in_stock
-方法添加到StorageItem
类中。在大致如下:
这样你就可以简化你对清单的理解:
^{pr2}$试试这个:
相关问题 更多 >
编程相关推荐