barker/barker/barker/models/guest_book.py

31 lines
1009 B
Python

import uuid
from datetime import datetime
from barker.models.meta import Base
from sqlalchemy import Column, DateTime, ForeignKey, Integer, text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
class GuestBook(Base):
__tablename__ = "guest_book"
id = Column(
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), default=uuid.uuid4
)
customer_id = Column("customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=False)
pax = Column("pax", Integer, nullable=False)
date = Column("creation_date", DateTime(), nullable=False)
customer = relationship("Customer")
def __init__(self, pax=None, id_=None, customer_id=None, customer=None):
self.customer_id = customer_id
self.pax = pax
self.id = id_
self.date = datetime.utcnow()
if customer is None:
self.customer_id = customer_id
else:
self.customer = customer