class Item(models.Model):
name = models.CharField(max_length=100, unique=True)
def admin_amount(self):
total = self.warehouse_set.all().aggregate(item=Sum('amount'))
return total['item']
class Warehouse(models.Model):
name = models.CharField(max_length=100, unique=True)
item = models.ForeignKey('Item', blank=True, null=True)
amount = models.IntegerField()
Create new field is wrong, but I cant do something like:
admin_amount.admin_order_field = 'admin_amount'
I found similar question but I encountered a problem with rewriting queryset() method(can't write something like qs.warehouse_set.all().annotate(models.Sum('amount'))
). Is there any way to adapt this solution for me or in my case, there is another solution?