syrusakbary/Flask-SuperAdmin

List view does not work with SQLAlchemy

iurisilvio opened this issue · 1 comments

Looks like SQLAlchemy models does not have a pk field. To access the primary key, use column_value.__mapper__.primary_key[0].name, but it can have some problem with composite primary keys.

Traceback (most recent call last):
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 36, in inner
    return f(self, *args, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 36, in inner
    return f(self, *args, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 36, in inner
    return f(self, *args, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/model/base.py", line 290, in list
    search_query=search_query)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 169, in render
    return render_template(template, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/templating.py", line 125, in render_template
    context, ctx.app)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/templating.py", line 107, in _render
    rv = template.render(context)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/model/list.html", line 3, in top-level template code
    {% set name = admin_view.get_display_name() %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/layout.html", line 21, in top-level template code
    {% block page_body %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/layout.html", line 71, in block "page_body"
    {% block body %}{% endblock %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/model/list.html", line 81, in block "body"
    {% with reference = admin_view.get_reference(admin_view.get_column(instance, c)) %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/model/base.py", line 128, in get_reference
    return '/admin/%s/%s/' % (model_view.endpoint, column_value.pk)
AttributeError: 'Endpoint' object has no attribute 'pk'

It was fixed by all these recent merges.