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()
utworzyć nowe pole jest źle, ale nie mogę zrobić coś takiegoDjango admin: Jak posortować kolumnę metodą niestandardową
admin_amount.admin_order_field = 'admin_amount'
znalazłem similar question ale wystąpił problem z przepisywania metodę queryset() (nie mogę napisać coś takiego jak qs.warehouse_set.all().annotate(models.Sum('amount'))
). Czy istnieje jakiś sposób, aby zaadaptować to rozwiązanie dla mnie lub w moim przypadku istnieje inne rozwiązanie?