Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Relationship in list and detail columns #22

Merged
merged 5 commits into from
Jan 21, 2022

Conversation

aminalaee
Copy link
Owner

Now Relationships can be used in list or detail columns:

class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    name = Column(String)
    email = Column(String)
    birthdate = Column(Date)

    addresses = relationship("Address", back_populates="user")


class Address(Base):
    __tablename__ = "addresses"

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey("users.id"))

    user = relationship("User", back_populates="addresses")


class UserAdmin(ModelAdmin, model=User):
    column_list = [User.id, User.name, User.email, User.addresses]


class AddressAdmin(ModelAdmin, model=Address):
    column_list = [Address.id, Address.user]
    name_plural = "Addresses"

Before this User.addresses and Address.user would not work with SQLAdmin.

@aminalaee aminalaee merged commit b7ed141 into main Jan 21, 2022
@aminalaee aminalaee deleted the allow-relationship-in-list-and-details-view branch January 21, 2022 10:42
@aminalaee aminalaee mentioned this pull request Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant