Skip to content

Instantly share code, notes, and snippets.

Created Jul 16, 2020
What would you like to do?
SA relationship updates
class ScannedPort:
label: str = ""
clsas ScannedDevice:
hostname: str = ""
ports: List[ScannedPort] = []
class Port(Base):
hostname = Column(String, ForeignKey("Device.hostname")
label = Column(String)
class Device(Base):
hostname = Column(String, primary_key=True)
ports = relationship(Port)
def existing_or_new(...): ...
def process(session: Session, from_network: ScannedDevice) -> Device:
device = existing_or_new(Device, hostname=from_network.hostname)
device.ports = [] # not actual code, but representative of the existing logic
for port in from_network.ports:
tmp = existing_or_new(Port, hostname=from_network.hostname, label=from_network.label)
return device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment