title: Creating one-to-one relationship Flask-SQLAlchemy
body: <p>I am trying to create a one-to-one relationship between a <code>Department</code> &amp; <code>Ticket</code> table. This way when looking inside of <code>Flask-Admin</code> a user would be able to see the <code>Department</code> name instead of the ID. </p>
  
  <p>I have tried to setup the relationship as follows:</p>
  
  <pre><code># Ticket Table
  class Tickets(db.Model):
      __tablename__ = 'tickets'
  
      ticketID = db.Column(db.Integer, nullable=False, primary_key=True, autoincrement=True, unique=True)
      cust_name = db.Column(db.String(50), nullable=False)
      cust_email = db.Column(db.String(50), nullable=False)
      cust_phone = db.Column(db.Integer, nullable=False)
      tix_dept = db.Column(db.Integer, db.ForeignKey('department.deptID'))
      tix_severity = db.Column(db.Integer, nullable=False)
      tix_msg = db.Column(db.String(500), nullable=False)
      tix_status = db.Column(db.String(10), nullable=False)
      tix_recv_date = db.Column(db.String(20), nullable=False)
      tix_recv_time = db.Column(db.Integer, nullable=False)
  
      # define relationship
      department = db.relationship('Departments')
  
  
  # Department Table
  class Departments(db.Model):
      __tablename__ = 'department'
  
      deptID = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)
      dept_name = db.Column(db.String(40), nullable=False)
      dept_empl = db.Column(db.String(40), nullable=False)
      dept_empl_phone = db.Column(db.Integer, nullable=False)
  </code></pre>
  
  <p>Then my <code>Flask-Admin</code> views are:</p>
  
  <pre><code>admin.add_view(TicketAdminView(Tickets, db.session, menu_icon_type='glyph', menu_icon_value='glyphicon-home'))
  admin.add_view(DepartmentAdminView(Departments, db.session))
  </code></pre>
  
  <p><strong>Admin Panel for Tickets:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/qaX8e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qaX8e.png" alt="Department Admin View"></a></p>
  
  <p><strong>Single Ticket Edit:</strong>
  <a href="https://i.stack.imgur.com/9tdVi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9tdVi.png" alt="Department Dropdown"></a></p>
  
  <p>How would I go about showing the <code>Department</code> name instead of the memory location?</p>