I have models as follows:
class Book(models.Model):
title = models.CharField(max_length=400)
def transactions_all_time(self):
latest_transactions = Transaction.objects.filter(book=self, transaction_type=0)
return len(latest_transactions)
class Transaction(models.Model):
book = models.ForeignKey(Book)
user = models.ForeignKey(User)
transaction_type = models.IntegerField(choices=TRANSACTION_TYPES)
I'd really like to find a way to list a table of books by title and transactions_all_time
in the admin interface, and make this table sortable on the transactions_all_time
field (or simply the number of related transactions, if that's easier).
I know that there isn't a straightforward way to do this - could anyone suggest a possible approach? Could I write some kind of custom admin view?
Thanks for your help.