code: def add_to_dict(self, an_object, extras=None):
          
          if an_object.id is None:
              raise ModelError("id must be set on object before adding to output.")
          if hasattr(an_object, "base_type"):
              mtype = an_object.base_type
          elif hasattr(an_object, "type"):
              if an_object.type in standard_types:
                  mtype = an_object.type
              else:
                  mtype = "custom_type"
          else:
              raise ModelError("Object does not have attribute 'base_type' or 'type', cannot add to output.")
          if mtype not in self.unordered_models:  # Catch any custom objects
              self.unordered_models[mtype] = OrderedDict()
  
          if hasattr(an_object, "add_to_dict"):
              an_object.add_to_dict(self.unordered_models)
  
          elif hasattr(an_object, "to_dict"):
              self.unordered_models[mtype][an_object.unique_hash] = an_object.to_dict(compression=self.compression)
          else:
              raise ModelError("Object does not have method 'to_dict', cannot add to output.")
docs: Convert models to json serialisable output
  
          :param an_object: An instance of a model object
          :param extras: A dictionary of extra variables that should be
          :return: