from sqlalchemy.inspection import inspect
from zou.app.utils.fields import serialize_value


class SerializerMixin(object):

    def serialize(self):
        attrs = inspect(self).attrs.keys()
        return {
            attr: serialize_value(getattr(self, attr)) for attr in attrs
        }

    @staticmethod
    def serialize_list(models):
        return [model.serialize() for model in models]

from sqlalchemy.inspection import inspect
from zou.app.utils.fields import serialize_value


class SerializerMixin(object):

    def serialize(self, obj_type=None):
        attrs = inspect(self).attrs.keys()
        obj_dict = {
            attr: serialize_value(getattr(self, attr)) for attr in attrs
        }
        obj_dict["type"] = obj_type or type(self).__name__
        return obj_dict

    @staticmethod
    def serialize_list(models, obj_type=None):
        return [model.serialize(obj_type=obj_type) for model in models]

Add object type to dict serialization
Add object type to dict serialization

  from sqlalchemy.inspection import inspect
  from zou.app.utils.fields import serialize_value
  
  
  class SerializerMixin(object):
  
-     def serialize(self):
+     def serialize(self, obj_type=None):
          attrs = inspect(self).attrs.keys()
-         return {
+         obj_dict = {
              attr: serialize_value(getattr(self, attr)) for attr in attrs
          }
+         obj_dict["type"] = obj_type or type(self).__name__
+         return obj_dict
  
      @staticmethod
-     def serialize_list(models):
+     def serialize_list(models, obj_type=None):
-         return [model.serialize() for model in models]
+         return [model.serialize(obj_type=obj_type) for model in models]
  
Add object type to dict serialization
## Code Before:
from sqlalchemy.inspection import inspect
from zou.app.utils.fields import serialize_value


class SerializerMixin(object):

    def serialize(self):
        attrs = inspect(self).attrs.keys()
        return {
            attr: serialize_value(getattr(self, attr)) for attr in attrs
        }

    @staticmethod
    def serialize_list(models):
        return [model.serialize() for model in models]

## Instruction:
Add object type to dict serialization
## Code After:
from sqlalchemy.inspection import inspect
from zou.app.utils.fields import serialize_value


class SerializerMixin(object):

    def serialize(self, obj_type=None):
        attrs = inspect(self).attrs.keys()
        obj_dict = {
            attr: serialize_value(getattr(self, attr)) for attr in attrs
        }
        obj_dict["type"] = obj_type or type(self).__name__
        return obj_dict

    @staticmethod
    def serialize_list(models, obj_type=None):
        return [model.serialize(obj_type=obj_type) for model in models]
