在我的 django 应用程序中,我在模型端进行计算,为此我仅使用一个返回元组的函数。我想将这个元组解析为几个属性
但我不能从那以后 -
TypeError: 'property' object is not iterable
def _get_total(self):
from inventory.models import Inventory
inventory_quantity = Inventory.objects.filter(material=self.id, is_active = True ).aggregate(Sum('quantity'))
from purchase.models import POmaterial
po_quantity = POmaterial.objects.filter(material=self.id, is_active = True).aggregate(Sum('quantity'))
from sales.models import SOproduct
so_quantity = SOproduct.objects.filter(product__material=self.id , is_active=True ).aggregate(Sum('quantity'))
actual_quantity = inventory_quantity + po_quantity - so_quantity
min_deficit = self.min_quantity - actual_quantity
max_deficit = self.max_quantity - actual_quantity
return inventory_quantity, po_quantity, so_quantity, min_deficit , max_deficit
total_inventory, total_po, total_so,min_deficit, max_deficit = property(_get_total())
有什么想法可以如何从此元组创建所有 5 个属性吗?
以下代码是否提供了必要的功能?
class MyClass(ClassParent):
_total_inventory = None
_total_po = None
...
...
def _get_total_(self):
...
# everything before the return clause
self._total_inventory = inventory_quantity
self._total_po = po_quantity
...
@property
def total_inventory(self):
if self._total_inventory is None:
self._get_total()
return self._total_inventory
@property
def total_po(self):
if self._total_po is None:
self._get_total()
return self._total_po
...
# And so on
我是一名优秀的程序员,十分优秀!