title: How to change the class attributes of the instance of the SQLAlchemyAutoSchema
body: <p>I have a flask_sqlalchemy model that I want to serialize its instance and a list of its instances using SQLAlchemyAutoSchema:</p>
  <pre><code>class TestModel(Model):
      id = Column(Integer, primary_key=True)
      test_comments = relationship(&quot;TestCommentModel&quot;, backref=backref(&quot;test&quot;, lazy=&quot;joined&quot;), 
          lazy=&quot;dynamic&quot;, foreign_keys=&quot;TestCommentModel.test_id&quot;)
  
  
      def find_by_id( ...  # 
      
      def find_all(...  # 
  
  
  </code></pre>
  <pre><code>class TestSchema(ma.SQLAlchemyAutoSchema):
  
      test_comments = ma.Nested(TestCommentSchema, many=True)
  
      class Meta:
          model = TestModel
          dump_only = (&quot;id&quot;,)
          load_instance = True
          include_fk = False
  </code></pre>
  <p>To do so, I create two instances of the above class as below:</p>
  <pre><code>test_schema = TestSchema()
  test_list_schema = TestSchema(many=True)
  
  test = TestModel.find_by_id(test_id)
  serialized_test = test_schema.dump(test)
  
  tests = TestModel.find_all()
  serialized_tests = {&quot;tests&quot;: test_list_schema.dump(tests)}
  
  </code></pre>
  <p>So what is serialized_test? It is what I want and it looks like this:</p>
  <pre><code>{&quot;id&quot;:1, &quot;comments&quot;: [&quot;id&quot;: 1, &quot;id&quot;:2]}
  </code></pre>
  <p>And what is serialized_tests? It looks like this:</p>
  <pre><code>{&quot;tests&quot;: [
      {&quot;id&quot;:1, &quot;comments&quot;: [&quot;id&quot;: 1, &quot;id&quot;:2]},
      {&quot;id&quot;:2, &quot;comments&quot;: [&quot;id&quot;: 3, &quot;id&quot;:4]},
      ]
  }
  </code></pre>
  <p>But I do not need comments. I just need:</p>
  <pre><code>{&quot;tests&quot;: [
      {&quot;id&quot;:1},
      {&quot;id&quot;:2},
      ]
  }
  </code></pre>
  <p>How can I have this without having to redefine another TestSchema such as TestListSchema?</p>
  <p>If I could do something like this it would be really helpful:</p>
  <pre><code>test_schema = TestSchema()
  test_list_schema = TestSchema(many=True)}
  test_list_schema = test_list_schema.pop(test_comment)  # Pseudo Code
  </code></pre>
  <p>What I am actually trying to do is to remove class attributes from the instance.</p>
  <p>Any solution of how to do that?</p>
  <p>Or if I could conditionally add attributes to the class</p>
  <pre><code># Pseudo code
  class TestSchema(ma.SQLAlchemyAutoSchema):
  
      if not many:
          test_comments = ma.Nested(TestCommentSchema, many=True)
  
      class Meta:
          model = TestModel
          dump_only = (&quot;id&quot;,)
          load_instance = True
          include_fk = False
  </code></pre>
  <p>any solution?</p>