Long time reader, first time asker. I'm a little unsure of how to express what I am trying to accomplish. Using Flask
and SQLAlchemy
, I am attempting to put data from a record (in this case, system.xxx) into a table. When I use system.xxx
, I also get the column name, as pictured below:
This is the code I'm using in my jinja template:
{% block page_content %}
<div class="page-header">
<h1>{{ system.serial }}</h1>
</div>
<hr width="80%">
<table class="table", border="5">
<tr>
<th>Status</th>
<th>Assignee</th>
</tr>
<tr>
<td>{{ system.status }}</td>
<td>{{ system.assignee }}</td>
</tr>
</table>
{% endblock %}
How can I access system.xxx
without getting the 'Status u
' or 'Assignee u
' column info? I've spent literally hours on the inter webs trying to figure this out, but I don't know how to properly phrase the question.
Added: the flask view.
@main.route('/system/<serial>', methods=['GET'])
def system(serial):
system = System.query.filter_by(serial=serial).first_or_404()
return render_template('system.html', system=system)
Added: the models in question
#table of individual systems
class System(db.Model):
__tablename__ = 'systems'
id = db.Column(db.Integer, primary_key=True)
serial = db.Column(db.String(64))
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
status_id = db.Column(db.Integer, db.ForeignKey('statuses.id'))
assignee_id = db.Column(db.Integer, db.ForeignKey('assignees.id'))
admin = db.Column(db.String)
def __repr__(self):
return '<System %r>' % self.serial
#table of assignees
class Assignee(UserMixin, db.Model):
__tablename__ = 'assignees'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
email = db.Column(db.String(64), unique=True, index=True)
systems = db.relationship('System', backref='assignee', lazy='dynamic')
def __repr__(self):
return '<Assignee %r>' % self.name
#table of status options
class Status(db.Model):
__tablename__ = 'statuses'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
systems = db.relationship('System', backref='status', lazy='dynamic')
@staticmethod
def insert_statuses():
statuses = ['Available', 'Loaned', 'Scrapped']
for status in statuses:
s = Status(name=status)
db.session.add(s)
db.session.commit()
def __repr__(self):
return '<Status %r>' % self.name