helloflask / bootstrap-flask

Bootstrap 4 & 5 helper for your Flask projects.
https://bootstrap-flask.readthedocs.io
Other
1.1k stars 189 forks source link

render_table() without SQLAlchemy not working #242

Closed vpathuis closed 1 year ago

vpathuis commented 1 year ago

For render_table(), the documentation states: data – An iterable of data objects to render. Can be dicts or class objects. When I try using this macro on a simple test list, I get an error: AttributeError: 'Item' object has no attribute '__table__'. It seems that SQLAlchemy is supposed to supply objects with __table__. All examples I've found use SQLAlchemy.

This is the test list:

@dataclass
class Item:
    col1: int
    col2: str

testlist = [
        Item(1, '2'),
        Item(3, '4')
    ]

Is using SQLAlchemy a requirement? If so, is the documentation correct?

PanderMusubi commented 1 year ago

Please see https://github.com/helloflask/bootstrap-flask/pull/243

vpathuis commented 1 year ago

Works perfect! The issue was not in the data but in the titles, which I'd assumed optional. I missed this sentence: if not provided, will automatically detect on provided data, currently only support SQLAlchemy object. Thanks a lot for reacting, and so quickly!

vpathuis commented 1 year ago

Could it be there is a similar simple solution for using the action buttons? When I use show_actions = Trueand add a model (class) and an edit_url, I get jinja2.exceptions.UndefinedError: 'type object' has no attribute 'query'.

PanderMusubi commented 1 year ago

Sounds like SQLAlchemy is needed for that, or you need your class to implement that. See base/table.html line 11.

vpathuis commented 1 year ago

Thnx for the suggestion. I'll consider my options :) Great work anyhow.