sqladmin icon indicating copy to clipboard operation
sqladmin copied to clipboard

Multiple Admin Instances result in wrong URL's to the views

Open hochstibe opened this issue 3 months ago • 1 comments

Checklist

  • [X] The bug is reproducible against the latest release or master.
  • [X] There are no similar issues or pull requests to fix it yet.

Describe the bug

I have an application with the option of extensions. My idea was to have an admin page for the main application and separate admin pages for the extensions.

You can have multiple instances of Admin running, but the links to the Views on the left point to wrong URL's.

  1. Start the app

  2. The Views are working correctly, when accessing with the url

    1. http://localhost:8000/admin1/user1/list
    2. http://localhost:8000/admin2/user2/list
  3. The navigation results in wrong url

    1. http://localhost:8000/admin2 --> Click on User2s -> Wrong URL http://localhost:8000/admin1/user2/list

Steps to reproduce the bug


from fastapi import FastAPI
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.orm import declarative_base
from sqladmin import Admin, ModelView


# DB -------------------------------------------------------------------------
Base = declarative_base()
engine = create_engine(
    "sqlite:///example.db",
    connect_args={"check_same_thread": False},
)


class User1(Base):
    __tablename__ = "users1"

    id = Column(Integer, primary_key=True)
    name = Column(String)


class User2(Base):
    __tablename__ = "users2"

    id = Column(Integer, primary_key=True)
    name = Column(String)


Base.metadata.create_all(engine)  # Create tables

# Main App -------------------------------------------------------------------
app = FastAPI()

# Admin ----------------------------------------------------------------------
admin1 = Admin(app, engine, base_url="/admin1")
admin2 = Admin(app, engine, base_url="/admin2")


class UserAdmin1(ModelView, model=User1):
    column_list = [User1.id, User1.name]


class UserAdmin2(ModelView, model=User2):
    column_list = [User2.id, User2.name]


admin1.add_view(UserAdmin1)
admin2.add_view(UserAdmin2)

Expected behavior

No response

Actual behavior

No response

Debugging material

No response

Environment

Tested on Windows, I could also test on Linux

  • Windows 10
  • Python: 3.10.2
  • Sqladmin: 0.16.1

Additional context

No response

hochstibe avatar Apr 03 '24 16:04 hochstibe