How to query data from 'grandparent' table to form_ajax_refs
#639
Replies: 3 comments 2 replies
-
Hmm..not sure what exactly the question is, but if your issue is that you can't select the right Rack instance then maybe update this: class Rack(...):
def __str__(self) -> str:
return f"{self.warehouse.name} - {self.rack_id}" I guess this will lead to some errors but that's solvable. Let me know if I got that right. |
Beta Was this translation helpful? Give feedback.
-
Yes it's definitely going in the right direction, but not without new roadblocks:
my engine and session are defined: SQLALCHEMY_DATABASE_URL = "sqlite+aiosqlite:///./sql_app.sqlite"
engine = create_async_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
async_session_maker = async_sessionmaker(
engine,
expire_on_commit=False,
)
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
async with async_session_maker() as session:
try:
yield session
finally:
await session.close() and Admin setup: def create_admin(
app: FastAPI, engine: Engine, auth_backend: AuthenticationBackend
) -> Admin:
admin = Admin(
app,
engine,
authentication_backend=auth_backend,
base_url="/admin",
session_maker=async_session_maker,
title="mSpaceLock Admin Panel",
)
return admin
def register_views_to_admin(
admin: Admin, views: list[Type[ModelView | BaseView]]
) -> None:
for view in views:
admin.add_view(view)
def setup_admin(app: FastAPI, engine: Engine) -> None:
authentication_backend = AdminAuth(secret_key=settings.SECRET_KEY)
admin = create_admin(app=app, engine=engine, auth_backend=authentication_backend)
register_views_to_admin(admin, views=admin_views) |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly if I wouldn't overcomplicate my project by going into asyncio connection to db, Or is there anything I can help to solve it to make it work with asyncio? |
Beta Was this translation helpful? Give feedback.
-
I've been looking for a solution for a few days already and I can't find the right keywords to find the solution which I should apply in that case. (including searching flask-admin-related topics)
Let's assume that we have three tables one to many relations to each other. Like Warehouse, Rack, and Locations, so we can have multiple warehouse each warehouse has multiple Racks and each Rack have multiple Locations on it.
Not sure if it's needed but let's assume the following models:
And of course question is related with sqladmin.
Once I create a new Location using this
form_ajax_refs
I can search and find field {warehouse_uuid} - {rack_id}, but of course I don't know which uuid belongs to which warehouse which is not very helpful. Once I create new location I would like to have visibility for {warehouse_name} - {rack_id} or even {company_name} - {warehouse_name} - {rack_id} so even if there is multiple same rack id on different warehouses I still able to choose the right one. How to solve it?BTW SQLAdmin is awesome and I really want to learn this tool indeph. Great work! @aminalaee
Beta Was this translation helpful? Give feedback.
All reactions