some base for form (text question)

This commit is contained in:
grey-cat-1908 2024-08-10 17:38:54 +00:00
parent 12ee0d4e7b
commit 41b3e5bb91
4 changed files with 35 additions and 0 deletions

13
database/form.py Normal file
View file

@ -0,0 +1,13 @@
from sqlalchemy import JSON
from sqlalchemy.orm import Mapped, mapped_column, relationship
from database import Base, User
class Form(Base):
__tablename__ = "forms"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
owner: Mapped[User] = relationship(User, cascade="all, delete")
data: Mapped[dict] = mapped_column(JSON)

View file

@ -5,6 +5,7 @@ from database import Base
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str] = mapped_column(unique=True)
password: Mapped[str]

21
models/form.py Normal file
View file

@ -0,0 +1,21 @@
from enum import Enum, auto
from pydantic import Field
from models import BaseModel
class QuestionType(Enum):
text = auto()
class BaseQuestion(BaseModel):
question_type: QuestionType
label: str = Field(min_length=1)
description: str | None = Field(None, min_length=1)
class TextQuestion(BaseQuestion):
question_type = QuestionType.text
min_length: int | None = None
max_length: int | None = None

Binary file not shown.