I am using Flask-Admin to manage several tables in my database and I've stumbled upon one issue. I have one-to-many relations in my database and the model is ok. If I want to add/delete/display records from/into my database via the Admin interface everything is ok. The only problem is that the Foreign Key fields are shown as object and I have no idea how to switch this to names.
class Locations(db.Model):
__tablename__ = "locations"
id = db.Column('id', db.Integer, primary_key=True)
name = db.Column('name', db.Unicode)
code = db.Column('code', db.Unicode)
servers = db.relationship('Servers', backref='location', lazy='dynamic')
subnets = db.relationship('Subnets', backref='location', lazy='dynamic')
class Servers(db.Model):
__tablename__ = "servers"
id = db.Column('id', db.Integer, primary_key=True)
serialnum = db.Column('serialnum', db.Unicode)
hostname = db.Column('hostname', db.Unicode)
type = db.Column('type', db.Unicode)
locationid = db.Column('locationid', db.Integer, db.ForeignKey('locations.id'))
idrac = db.relationship('Idracs', backref='server', lazy='dynamic')
interface = db.relationship('Interfaces', backref='server', lazy='dynamic')
class ServersView(ModelView):
column_searchable_list = ('hostname', 'type', 'serialnum')
column_list = ('location', 'hostname', 'type', 'serialnum')
form_columns = [ 'location', 'hostname', 'type', 'serialnum' ]
admin.add_view(ServersView(Servers, db.session))
When I want to list or create a new record I would like to see the name of the location, not the object main.Locations .
Can anyone give me a small hint ?
Thanks in advance!