I have a rather complicated custom method of the Django model. This is visible in the admin interface, and now I would like to make it sortable in the admin interface.
I added admin_order_field as recommended in this previous question , but I don't quite understand what else I need to do.
class Book(models.Model): id = models.IntegerField(primary_key=True) title = models.CharField(max_length=200) library_id = models.CharField(max_length=200, unique=True) def current_owner(self): latest_transaction = Transaction.objects.filter(book=self)[:1] if latest_transaction: if latest_transaction[0].transaction_type==0: return latest_transaction[0].user.windows_id return None current_owner.admin_order_field = 'current_owner'
Currently, when I click on the current_owner field in the admin interface, Django gives me
FieldError at /admin/books/book/ Cannot resolve keyword 'current_owner' into field
Do I need to do BookManager? If so, what code should I use? This is not a simple graph, as an example in the previous question, so help will be appreciated :)
Thanks!
source share