Add basic card management
This commit is contained in:
38
models.py
38
models.py
@@ -1,13 +1,35 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from __future__ import annotations
|
||||
from typing import List, Optional
|
||||
|
||||
Base = declarative_base()
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy import Column, Integer, String, Boolean
|
||||
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase, relationship
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, index=True)
|
||||
email = Column(String, nullable=True)
|
||||
password = Column(String)
|
||||
is_admin = Column(Boolean, default=False)
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
name: Mapped[str]
|
||||
email: Mapped[Optional[str]]
|
||||
password: Mapped[str]
|
||||
is_admin: Mapped[bool]
|
||||
|
||||
class AccessAuthorization(Base): #parent
|
||||
__tablename__ = "access_authorizations"
|
||||
|
||||
name: Mapped[str] = mapped_column(primary_key=True, index=True)
|
||||
is_active: Mapped[bool]
|
||||
card_id: Mapped[List["Card"]] = relationship(back_populates="user")
|
||||
|
||||
class Card(Base): #child
|
||||
__tablename__ = "cards"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
uuid: Mapped[str] = mapped_column(index=True)
|
||||
user_id = mapped_column(ForeignKey("access_authorizations.name"))
|
||||
user: Mapped["AccessAuthorization"] = relationship(back_populates="card_id")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user