column_ details_ List #80
Replies: 3 comments 5 replies
-
Hey, thanks for reporting this. |
Beta Was this translation helpful? Give feedback.
-
# -*- coding:utf-8 -*-
import uvicorn
from fastapi import FastAPI
from sqladmin import Admin, ModelAdmin
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.orm import declarative_base, relationship, backref
app = FastAPI()
Base = declarative_base()
engine = create_engine('sqlite:///foo.db?check_same_thread=False', echo=True, future=True)
admin = Admin(app, engine)
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
name = Column(String(10))
def __repr__(self):
return self.name
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
name = Column(String(10))
parent_id = Column(Integer, ForeignKey('parent.id'))
parent = relationship("Parent", backref=backref("child"))
def __repr__(self):
return self.name
Base.metadata.create_all(bind=engine)
class ParentAdmin(ModelAdmin, model=Parent):
column_list = [Parent.id, Parent.name]
class ChildAdmin(ModelAdmin, model=Child):
column_list = [Child.id, Child.name]
# if dont't set column_details_list, or all properties are included, and the operation is normal
column_details_list = [Child.id, Child.name, Child.parent_id, Child.parent]
# if i just want to show Child.id and Child.name ,there has some 500 error
# column_details_list = [Child.id,Child.name]
admin.register_model(ParentAdmin)
admin.register_model(ChildAdmin)
if __name__ == '__main__':
uvicorn.run(app="server:app", host="0.0.0.0", port=8000, workers=1, reload=True) |
Beta Was this translation helpful? Give feedback.
-
my env: ERROR: Exception in ASGI application |
Beta Was this translation helpful? Give feedback.
-
Parameter column_ details_ List doesn't work and will report an error (Sqlalchemy. Orm. Exc.detachedinstanceerror: parent instance < label at 0x1a13f9df280 > is not bound to a session; lazy load operation of attribute 'label2article' cannot proceed (background on this error at: https://sqlalche.me/e/14/bhk3 )
), because the associated properties are not loaded unless model. Is set Lazy = 'noload', but this will still show all columns
Beta Was this translation helpful? Give feedback.
All reactions