93 lines
3.8 KiB
Python
93 lines
3.8 KiB
Python
from sqlalchemy import (
|
|
Boolean,
|
|
CheckConstraint,
|
|
ForeignKey,
|
|
Integer,
|
|
SmallInteger,
|
|
String,
|
|
Text,
|
|
false,
|
|
true,
|
|
)
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class Service(TimestampMixin, Base):
|
|
__tablename__ = "services"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
title: Mapped[str] = mapped_column(String(150))
|
|
slug: Mapped[str] = mapped_column(String(170), unique=True, index=True)
|
|
short_description: Mapped[str | None] = mapped_column(String(300))
|
|
description: Mapped[str | None] = mapped_column(Text)
|
|
icon: Mapped[str | None] = mapped_column(String(60)) # optional icon name for the frontend
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0, server_default="0")
|
|
is_published: Mapped[bool] = mapped_column(Boolean, default=False, server_default=false())
|
|
|
|
# Single watermarked image (paths relative to UPLOAD_DIR)
|
|
image_original_path: Mapped[str | None] = mapped_column(String(300))
|
|
image_watermarked_path: Mapped[str | None] = mapped_column(String(300))
|
|
image_thumbnail_path: Mapped[str | None] = mapped_column(String(300))
|
|
|
|
|
|
class Testimonial(TimestampMixin, Base):
|
|
__tablename__ = "testimonials"
|
|
__table_args__ = (CheckConstraint("rating BETWEEN 1 AND 5", name="rating_range"),)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
customer_name: Mapped[str] = mapped_column(String(150))
|
|
designation: Mapped[str | None] = mapped_column(String(150))
|
|
location: Mapped[str | None] = mapped_column(String(150))
|
|
content: Mapped[str | None] = mapped_column(Text) # quote; optional for video-only reviews
|
|
video_url: Mapped[str | None] = mapped_column(String(500)) # YouTube link or direct .mp4 URL
|
|
rating: Mapped[int] = mapped_column(SmallInteger, default=5, server_default="5")
|
|
project_id: Mapped[int | None] = mapped_column(
|
|
ForeignKey("projects.id", ondelete="SET NULL"), index=True
|
|
)
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0, server_default="0")
|
|
is_published: Mapped[bool] = mapped_column(Boolean, default=True, server_default=true())
|
|
|
|
# Optional video still / customer photo (watermarked like every admin upload)
|
|
image_original_path: Mapped[str | None] = mapped_column(String(300))
|
|
image_watermarked_path: Mapped[str | None] = mapped_column(String(300))
|
|
image_thumbnail_path: Mapped[str | None] = mapped_column(String(300))
|
|
|
|
|
|
class Subscriber(TimestampMixin, Base):
|
|
"""Footer newsletter sign-ups."""
|
|
|
|
__tablename__ = "subscribers"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, server_default=true())
|
|
|
|
|
|
class ContactMessage(TimestampMixin, Base):
|
|
__tablename__ = "contact_messages"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String(150))
|
|
email: Mapped[str] = mapped_column(String(255), index=True)
|
|
phone: Mapped[str | None] = mapped_column(String(20))
|
|
subject: Mapped[str | None] = mapped_column(String(200))
|
|
message: Mapped[str] = mapped_column(Text)
|
|
is_read: Mapped[bool] = mapped_column(Boolean, default=False, server_default=false(), index=True)
|
|
|
|
|
|
class SiteContent(TimestampMixin, Base):
|
|
"""Key/value blocks of editable copy (hero text, about text, stats, contact info...).
|
|
|
|
The frontend decides which keys exist; values are JSON so each block can hold
|
|
the exact fields its Figma section needs without schema changes.
|
|
"""
|
|
|
|
__tablename__ = "site_content"
|
|
|
|
key: Mapped[str] = mapped_column(String(80), primary_key=True)
|
|
value: Mapped[dict] = mapped_column(JSONB)
|
|
updated_by_id: Mapped[int | None] = mapped_column(ForeignKey("admins.id", ondelete="SET NULL"))
|