Обновление приложения
This commit is contained in:
26
backend/app/models/location.py
Normal file
26
backend/app/models/location.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from sqlalchemy import String, Text, Numeric, ForeignKey, DateTime, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Location(Base):
|
||||
__tablename__ = "locations"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
user_id: Mapped[int | None] = mapped_column(ForeignKey("users.id"), nullable=True) # None = system location
|
||||
name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
type: Mapped[str | None] = mapped_column(String(50)) # store, bank, atm, online, other
|
||||
address: Mapped[str | None] = mapped_column(Text)
|
||||
city: Mapped[str | None] = mapped_column(String(100))
|
||||
country: Mapped[str | None] = mapped_column(String(100))
|
||||
latitude: Mapped[Decimal | None] = mapped_column(Numeric(9, 6))
|
||||
longitude: Mapped[Decimal | None] = mapped_column(Numeric(9, 6))
|
||||
parent_id: Mapped[int | None] = mapped_column(ForeignKey("locations.id"), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
user: Mapped["User | None"] = relationship("User", back_populates="locations")
|
||||
parent: Mapped["Location | None"] = relationship("Location", remote_side="Location.id", back_populates="children")
|
||||
children: Mapped[list["Location"]] = relationship("Location", back_populates="parent")
|
||||
operations: Mapped[list] = relationship("Operation", back_populates="location")
|
||||
Reference in New Issue
Block a user