title: SQLAlchemy how to define two models for the same table
body: <p>I have a single table, and one of the columns is a varchar with two values ('groupA','groupB')</p>
  <p>When I created my models I wanted to achieve two things:</p>
  <ol>
  <li>model for groupA - that hold X amount of related functions</li>
  <li>model for groupB - that hold Y amount of related functions</li>
  </ol>
  <p>the functions are not the same for both models, though they represents the <em>same</em> table:</p>
  <pre><code>class GroupA(Base):
    __tablename__ = 'groups' 
  
    id = Column('id', Integer, primary_key=True)
    name  = Column('name',  String(80))
    group_type = Column('type', String(15), default=&quot;groupA&quot;)
  </code></pre>
  <p>And for groupB:</p>
  <pre><code>class GroupB(Base):
    __tablename__ = 'groups' 
  
    id = Column('id', Integer, primary_key=True)
    name  = Column('name',  String(80))
    group_type = Column('type', String(15), default=&quot;groupB&quot;)
  </code></pre>
  <p>So GroupA &amp; B are the same table: &quot;groups&quot;, but GroupA has 100 rows, groupB has 20rows</p>
  <p>I want to prevent writing this all the time:</p>
  <pre><code>session.query(GroupA).filter(group_type = 'groupA')
  session.query(GroupB).filter(group_type = 'groupB')
  </code></pre>
  <p>How can I configure my model with some kind of a &quot;fitler&quot; that when I'll query.all() it will return the data relavent for each model ? right now I receive all data in both models no matter which model I queried...</p>
  <p>Thanks in advance.</p>
  <h1>EDIT with the solution based on answer</h1>
  <p>To use inheritence I had to change the entire structure to</p>
  <pre><code>class Group(Base):
     id = Column('id', Integer, primary_key=True)
     name  = Column('name',  String(80))
     group_type = Column('type', String(15))
  
      __mapper_args__ = {
          'polymorphic_on': g_type,
          'polymorphic_identity': 'Group'
      }
  
  # Replacing Base =&gt; Group
  class GroupA(Group):
     __mapper_args__ = {
        'polymorphic_identity': 'GroupA'
     }
  
  class GroupB(Group):
     __mapper_args__ = {
        'polymorphic_identity': 'GroupB'
     }
  </code></pre>
  <p>And it's working, thank you very much !</p>