#NEWLINE# def save_form_data( self , instance , data ) : #NEWLINE# #INDENT# '\n        The ``KeywordsWidget`` field will return data as a string of\n        comma separated IDs for the ``Keyword`` model - convert these\n        into actual ``AssignedKeyword`` instances. Also delete\n        ``Keyword`` instances if their last related ``AssignedKeyword``\n        instance is being removed.\n        ' #NEWLINE# from mezzanine.generic.models import Keyword #NEWLINE# related_manager = getattr ( instance , self . name ) #NEWLINE# old_ids = [ str ( a . keyword_id ) for a in related_manager . all ( ) ] #NEWLINE# new_ids = data . split ( ',' ) #NEWLINE# removed_ids = ( set ( old_ids ) - set ( new_ids ) ) #NEWLINE# related_manager . all ( ) . delete ( ) #NEWLINE# if data : #NEWLINE# #INDENT# data = [ related_manager . create ( keyword_id = i ) for i in new_ids ] #NEWLINE# #UNINDENT# Keyword . objects . delete_unused ( removed_ids ) #NEWLINE# super ( KeywordsField , self ) . save_form_data ( instance , data )