def get_save_comment(self): comments = [] short_comments = [] previous = self.instance.pk and self.instance.tags or None d = TagsFieldDiff(previous, self.cleaned_data['tags']) diff = d.get_diff() deleted = ['"%s"' % t.name for t in diff['deleted']] added = ['"%s"' % t.name for t in diff['added']] if deleted: tag_name_pluralized = self.pluralize_tag(deleted) comments.append(ungettext( 'removed %(name)s %(deleted)s.', 'removed %(name)s %(deleted)s.', len(deleted) ) % { 'deleted': ', '.join(deleted), 'name': tag_name_pluralized } ) short_comments.append(ungettext( 'removed %(count)i %(name)s.', 'removed %(count)i %(name)s.', len(deleted) ) % { 'count': len(deleted), 'name': tag_name_pluralized } ) if added: tag_name_pluralized = self.pluralize_tag(added) comments.append(ungettext( 'added %(name)s %(added)s.', 'added %(name)s %(added)s.', len(added) ) % { 'added': ', '.join(added), 'name': tag_name_pluralized } ) short_comments.append(ungettext( 'added %(count)i %(name)s.', 'added %(count)i %(name)s.', len(added) ) % { 'count': len(added), 'name': tag_name_pluralized } ) if not comments: return _('no changes made') comments = _(' and ').join(comments) # with lots of tags, this can get too long for db field if len(comments) > 140: return _(' and ').join(short_comments) return comments