First commit.
This commit is contained in:
commit
a3e676a0b0
13 changed files with 346 additions and 0 deletions
18
example_app/models.py
Normal file
18
example_app/models.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from typing import List
|
||||
from sqlalchemy import String, ForeignKey
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
||||
from crudkit import CrudMixin
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
class Author(CrudMixin, Base):
|
||||
__tablename__ = "author"
|
||||
name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
books: Mapped[List["Book"]] = relationship(back_populates="author", cascade="all, delete-orphan")
|
||||
|
||||
class Book(CrudMixin, Base):
|
||||
__tablename__ = "book"
|
||||
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
author_id: Mapped[int] = mapped_column(ForeignKey("author.id"), nullable=False)
|
||||
author: Mapped[Author] = relationship(back_populates="books")
|
||||
Loading…
Add table
Add a link
Reference in a new issue