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

One-To-Many relationship, Select or Add Inline model Option in the Parent Model View? #2364

Open
hasansezertasan opened this issue Jun 14, 2023 · 1 comment

Comments

@hasansezertasan
Copy link
Member

hasansezertasan commented Jun 14, 2023

Hey everyone 👋

I've been searching about it and I found that we could use InlineFormAdmin and InlineOneToOneModelConverter for one-to-one inline models and a similar approach for one-to-many models but my goal is to offer an option.

Search and select the child model, if it doesn't exist, then create it while creating the parent model. Is this possible? As far as I searched, I couldn't find any method of doing this.

Let's say that we have two tables, owners and cars. A car can only have one owner but an owner can have multiple cars. Let's say that I have more columns to record in the database and I want to add Cars first with their Owners but what if the owner is already in my database? I may search id and select in on the same create form but what if not, then I should go to the Owner View and add an Owner and then I should come back and edit the Owner, right? My goal is basically add or select an owner when creating a car record.

class Owner(Base):
    id = Column(Integer, primary_key=True)
    date_created = Column(DateTime, default=datetime.utcnow)
    cars = relationship("Car", back_populates="owners")

class Car(Base):
    id = Column(Integer, primary_key=True)
    date_created = Column(DateTime, default=datetime.utcnow)
    plate = Column(String)
    owner_id = Column(Integer, ForeignKey("owner.id"))
    owner = relationship("Owner", back_populates="cars")
@hasansezertasan hasansezertasan changed the title One-To-One relationship, Select or Add Inline model in the Parent Model View? One-To-Many relationship, Select or Add Inline model Option in the Parent Model View? Jun 17, 2023
@hasansezertasan
Copy link
Member Author

hasansezertasan commented Jul 20, 2024

Related: #390, #1248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant