original_docstring: 
          Useful to retag all batches after creating new tags.
          Existing tags should be cleared first.
          
docstring: Useful to retag all batches after creating new tags.
  Existing tags should be cleared first.
docstring_tokens: Useful to retag all batches after creating new tags . Existing tags should be cleared first .
code: def retag_edits(cls, edits):
          """
          Useful to retag all batches after creating new tags.
          Existing tags should be cleared first.
          """
          batch_to_tags = defaultdict(set)
          for edit in edits:
              tags = cls.extract(edit)
              missing_tags = [t for t in tags if t.id not in edit.batch.tag_ids]
              batch_to_tags[edit.batch_id].update(missing_tags)
  
          ThroughModel = cls.batches.through
          instances = []
          for batch_id, tags in batch_to_tags.items():
              for tag in tags:
                  instances.append(ThroughModel(batch_id=batch_id,tag_id=tag.id))
  
          ThroughModel.objects.bulk_create(instances)
code_tokens: def retag_edits ( cls , edits ) : batch_to_tags = defaultdict ( set ) for edit in edits : tags = cls . extract ( edit ) missing_tags = [ t for t in tags if t . id not in edit . batch . tag_ids ] batch_to_tags [ edit . batch_id ] . update ( missing_tags ) ThroughModel = cls . batches . through instances = [ ] for batch_id , tags in batch_to_tags . items ( ) : for tag in tags : instances . append ( ThroughModel ( batch_id = batch_id , tag_id = tag . id ) ) ThroughModel . objects . bulk_create ( instances )
short_docstring: Useful to retag all batches after creating new tags.
short_docstring_tokens: Useful to retag all batches after creating new tags .
comment: """
          Useful to retag all batches after creating new tags.
          Existing tags should be cleared first.
          """