code: def add_all_exchange_reactions(model, compartment, allow_duplicates=False):
      
  
      all_reactions = {}
      if not allow_duplicates:
          # TODO: Avoid adding reactions that already exist in the database.
          # This should be integrated in the database.
          for rxnid in model.database.reactions:
              rx = model.database.get_reaction(rxnid)
              all_reactions[rx] = rxnid
  
      added = set()
      added_compounds = set()
      initial_compounds = set(model.compounds)
      reactions = set(model.database.reactions)
      for model_compound in initial_compounds:
          compound = model_compound.in_compartment(compartment)
          if compound in added_compounds:
              continue
  
          rxnid_ex = create_exchange_id(reactions, compound)
  
          reaction_ex = Reaction(Direction.Both, {compound: -1})
          if reaction_ex not in all_reactions:
              model.database.set_reaction(rxnid_ex, reaction_ex)
              reactions.add(rxnid_ex)
          else:
              rxnid_ex = all_reactions[reaction_ex]
  
          if not model.has_reaction(rxnid_ex):
              added.add(rxnid_ex)
          model.add_reaction(rxnid_ex)
          added_compounds.add(compound)
  
      return added
docs: Add all exchange reactions to database and to model.
  
      Args:
          model: :class:`psamm.metabolicmodel.MetabolicModel`.