Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:31:47+00:00 2026-05-19T01:31:47+00:00

I have a reasonably complex custom Django model method. It’s visible in the admin

  • 0

I have a reasonably complex custom Django model method. It’s visible in the admin interface, and I would now like to make it sortable in the admin interface too.

I’ve added admin_order_field as recommended in this previous question, but I don’t fully 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 make a BookManager too? If so, what code should I use? This isn’t a simple Count like the example in the previous question, so help would be appreciated 🙂

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:31:48+00:00Added an answer on May 19, 2026 at 1:31 am

    The Django admin won’t order models by the result of a method or any other property that isn’t a model field (i.e. a database column). The ordering must be done in the database query, to keep things simple and efficient.

    The purpose of admin_order_field is to equate the ordering of a non-field property to the ordering of something that is a field.

    For example, a valid values current_owner.admin_order_field could be id, title or library_id. Obviously none of these makes sense for your purpose.

    One solution would be to denormalise and always store current_owner as a model field on Book; this could be done automatically using a signal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a reasonably complex layout problem: I would like to have a main
I have 4 reasonably complex r scripts that are used to manipulate csv and
I have a reasonably complex MySQL query being run on another developer's database. I
I have a project that creates a disk image and would like to use
I have a reasonably complex macro that I need to run on multiple different
I have a reasonably complex XML document which I want to flatten down to
I would like to have a reference between two entities stored in the RavenDB
In Django, if I have a model class, e.g. from django.db import models class
I'm currently developing a reasonably complex HTML5 application. Up to now, I've been testing
I'm currently developing a reasonably complex HTML5 application. Up to now, I've been testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.