Semaine 7
This commit is contained in:
30
Semaine_07/Jour_04/bank/entities/services.py
Normal file
30
Semaine_07/Jour_04/bank/entities/services.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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})"
|
||||
Reference in New Issue
Block a user