Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

Why can't use function in hybrid_property? #130

Closed gotounix closed 3 years ago

gotounix commented 4 years ago
@hybrid_property
def word_insensitive(self):
    return self.word.lower()
ColumnDT(Title.word_insensitive, mData='word_insensitive'),

I got errors:

AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Title.word_insensitive has an attribute 'lower'

I test str.split() can't used neither.

pndmix commented 4 years ago

Try it, I solved a similar problem.

from sqlalchemy import func

@hybrid_property
def word_insensitive(self):
    return func.lower(self.word)
tdamsma commented 3 years ago

The point of hybrid properties is that you can specify the same logic in both Python and SQL. If you don't specify the SQL, then that doesn't work. Check the hybrid prroperty docs