Skip to content
Snippets Groups Projects
Commit 7ac9c09d authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add Tag table

hosttags table required for the many-to-many relationship
See http://flask-sqlalchemy.pocoo.org/2.3/models/#many-to-many-relationships
parent 03740331
No related branches found
No related tags found
No related merge requests found
......@@ -381,6 +381,18 @@ class Network(db.Model):
}
# Table required for Many-to-Many relationships between hosts and tags
hosttags_table = db.Table(
'hosttags',
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
db.Column('host_id', db.Integer, db.ForeignKey('host.id'), primary_key=True)
)
class Tag(QRCodeMixin, db.Model):
pass
class Host(db.Model):
id = db.Column(db.Integer, primary_key=True)
network_id = db.Column(db.Integer, db.ForeignKey('network.id'), nullable=False)
......@@ -390,6 +402,8 @@ class Host(db.Model):
mac_id = db.Column(db.Integer, db.ForeignKey('mac.id'))
cnames = db.relationship('Cname', backref='host')
tags = db.relationship('Tag', secondary=hosttags_table, lazy='subquery',
backref=db.backref('hosts', lazy=True))
def __init__(self, **kwargs):
# Automatically convert network to an instance of Network if it was passed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment