Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set Column.accessor when binding a column to allow order() method to use its value #979

Merged
merged 1 commit into from
Dec 21, 2024

Conversation

jieter
Copy link
Owner

@jieter jieter commented Dec 20, 2024

This allows using the accessor to be used as part of an expression, for example when using a custom column with an order() method:

class UserNameColumn(tables.Column):
    def order(self, queryset, is_descending):
        order_field = Lower(self.accessor)
        if is_descending:
            order_field = order_field.desc()
        return queryset.order_by(order_field), True


table = SimpleTable(MEMORY_DATA)
self.assertEqual(table.columns["col1"].accessor, "alpha__upper__isupper")
self.assertEqual(table.columns["col2"].accessor, "alpha__upper")
self.assertEqual(table.columns["beta"].accessor, "beta")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this change, the accessor would equal None

@jieter jieter merged commit df4fea9 into master Dec 21, 2024
28 checks passed
@jieter jieter deleted the feature/explicit-accessor branch December 21, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant