Administrator Django: jak sortować kolumny według metody niestandardowej
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()
Tworzenie nowego pola jest złe, ale nie mogę zrobić czegoś takiego:
admin_amount.admin_order_field = 'admin_amount'
znalazłempodobne pytanie ale napotkałam problem z przepisaniem metody queryset () (nie mogę napisać czegoś takiegoqs.warehouse_set.all().annotate(models.Sum('amount'))
). Czy jest jakiś sposób na dostosowanie tego rozwiązania dla mnie lub w moim przypadku, jest inne rozwiązanie?