title: Flask-Admin - Foreign Key Lookup Create if Not found
body: <p>I have a Flask Admin section, which uses SQLAlchemy Models to build the forms.</p>
  
  <p>I have not been able to figure out how to do an operation like "If Foreign key Not Found, insert a new record".</p>
  
  <p>For instance. Take the following SQLAlchemy Models</p>
  
  <pre><code>class Room(Base):
      __tablename__ = 'rooms'
  
      id = sqlalchemy.Column(sqlalchemy.Integer,
                             primary_key=True,
                             autoincrement=True
                             )
      description = sqlalchemy.Column(sqlalchemy.String(256))
      name = sqlalchemy.Column(sqlalchemy.String(32))
      phone_numbers = relationship('RoomPhoneNumber',
                                   backref='room')
      intercom_numbers = relationship('RoomIntercomNumber',
                                      backref='room')
  
  
  class RoomPhoneNumber(Base):
      """
      A phone number assigned to a given room.
      """
      __tablename__ = 'roomextensions'
      id = sqlalchemy.Column(sqlalchemy.Integer,
                             primary_key=True,
                             autoincrement=True
                             )
      number = sqlalchemy.Column(sqlalchemy.String(25))
      room_id = sqlalchemy.Column(sqlalchemy.Integer,
                                  sqlalchemy.ForeignKey(Room.id)
                                  )
  </code></pre>
  
  <p><strong>Admin ModelView</strong></p>
  
  <pre><code>class RoomAdmin(sqla.ModelView):
      def is_accessible(self):
          return login.current_user.is_admin
      column_auto_select_related = True
      column_searchable_list = ('name', 'description')
      column_display_pk = True
      column_list = ('id', 'description', 'name', 'phone_numbers', 'intercom_numbers')
      form_columns = ['description', 'name', 'phone_numbers', 'intercom_numbers']
  </code></pre>
  
  <p>The Room Admin Model does not allow me to type in a new <code>RoomPhoneNumber</code> I would like to be able to input a Phone Number from the Room Admin model, and if it is not found, simply insert it with the current generated room ID, without having to move over to the <code>RoomPhoneNumberAdmin</code> Page</p>
  
  <p>Is there a configuration in Flask-Admin I am missing, or is this a poor database design problem?</p>
  
  <p>Thanks for reading, can post further information if required. </p>
  
  <p>Wont allow value that does not exist
      <a href="https://i.stack.imgur.com/vxDUW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vxDUW.png" alt="enter image description here"></a></p>