30 lines
951 B
Python
30 lines
951 B
Python
from sqlalchemy import ForeignKey, Column, Integer, String, Float, Table
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from database.connection import Base
|
|
|
|
# Table d'association
|
|
client_service = Table(
|
|
'client_service',
|
|
Base.metadata,
|
|
Column('client_id', Integer, ForeignKey('clients.id'), primary_key= True),
|
|
Column('service_id', Integer, ForeignKey('clients.id'), primary_key= True)
|
|
)
|
|
|
|
class Service(Base):
|
|
__tablename__ = "Services"
|
|
|
|
id = Column(Integer, primary_key= True, autoincrement= True)
|
|
name = Column(String(200), nullable= False)
|
|
description = Column(String(500))
|
|
monthly_price = Column(Float)
|
|
|
|
clients = relationship("Client", back_populates= "services", secondary= client_service)
|
|
|
|
def __init__(self, name, description= "", price= 0):
|
|
self.name = name
|
|
self.description = description
|
|
self.monthly_price = price
|
|
|
|
def __repr__(self):
|
|
return f"Service({self.name})" |