Skip to content

Support for ordering on non-indexed properties #51

@zerolab

Description

@zerolab

e.g. https://wagtailcms.slack.com/archives/C81FGJR2S/p1762869979474629

Using the image listing, if you search by something and try to order by the usage count you get:

Cannot sort search results with field "usage_count". Please add index.FilterField("usage_count") to CustomImage.search_fields.

However, usage_count is an annotation on the results queryset, so adding index.FilterField("usage_count") fails with images.CustomImage: (modelsearch.W004) CustomImage.search_fields contains non-existent field 'usage_count', as expected. The workaround in this case is to define

def usage_count(self):
    return self.get_usage().count()

on the CustomImage object, but IMHO, this should just work.

Note: this is not limited to just core images/docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions