I ended up using a self-referential many-to-many association table, where one structure can be related to many other structures in the same table.
In Python's Flask-SQLAlchemy library, this is how the association table is represented:
structure_structure_rel = db.Table(
'structure_structure_rel',
db.Column(
'primary_structure_id',
INTEGER,
db.ForeignKey('public.structures.id', ondelete="CASCADE"),
primary_key=True
),
db.Column(
'secondary_structure_id',
INTEGER,
db.ForeignKey('public.structures.id', ondelete="CASCADE"),
primary_key=True
),
schema='public'
)
And here's the actual "structures" table, represented as a class in the SQLAlchemy object relational model (ORM):
class Structure(db.Model):
"""Create a public.structures PostgreSQL table representation
for use in Python Flask-SQLAlchemy
"""
__tablename__ = 'structures'
__table_args__ = {"schema": "public"}
id = db.Column(INTEGER, primary_key=True)
...
# Super-cool self-referential many-to-many relationship
secondary_structure_id = db.relationship(
'Structure',
secondary=structure_structure_rel,
primaryjoin=(structure_structure_rel.c.primary_structure_id == id),
secondaryjoin=(structure_structure_rel.c.secondary_structure_id == id),
backref=db.backref('primary_structure_id', lazy='select'),
lazy='select'
)
I can then use both those relationship "columns" (i.e. primary_structure_id and secondary_structure_id) in Flask-Admin, which is really nice.
-Sean