Sort/search on custom attributes #600
Replies: 2 comments 5 replies
-
hey @johanboekhoven , It might help if you paste a very minimal example here, |
Beta Was this translation helpful? Give feedback.
-
@aminalaee Ok, I have the best solution possible in my situation I think! class TaskView(ModelView, model=Task):
column_default_sort = (models.Task.id, True) # colomn, desc
list_query = select(models.Task).join(models.Task.asset)
column_list = [
models.Task.id,
models.Asset.client_id,
column_sortable_list = [
models.Task.id,
models.Asset.client_id,
column_searchable_list = [
models.Task.id,
models.Asset.client_id,
class Task(Base):
__tablename__ = "tasks"
id = Column(Integer, primary_key=True)
@property
def client_id(self):
if self.asset is None:
return ""
return self.asset.client_id So the basic join on the list_query suddenly makes everything very transparent, *edit: in order for viewing the property you need to declare it as property, I forgot the ca's where still there when writing this message.. |
Beta Was this translation helpful? Give feedback.
-
Am I correct to assume we can't do search and sort on custom attributes?
https://aminalaee.dev/sqladmin/cookbook/display_custom_attributes/
for custom attribute : 'client_id'
column_list=[models.Task.id, 'client_id'] ✔
column_sortable_list=[models.Task.id, 'client_id'] ❌
column_searchable_list=[models.Task.id, 'client_id'] ❌
Is there logic that I can implement to make that work too, something in the list_query perhaps?
Thanks, would love to have custom attributes searchable and sortable.
Beta Was this translation helpful? Give feedback.
All reactions