#NEWLINE# def remove_objects_not_in( self , objects_to_keep , verbosity ) : #NEWLINE# #INDENT# '\n        Deletes all the objects in the database that are not in objects_to_keep.\n        - objects_to_keep: A map where the keys are classes, and the values are a\n         set of the objects of that class we should keep.\n        ' #NEWLINE# for class_ in objects_to_keep . keys ( ) : #NEWLINE# #INDENT# current = class_ . objects . all ( ) #NEWLINE# current_ids = set ( [ x . pk for x in current ] ) #NEWLINE# keep_ids = set ( [ x . pk for x in objects_to_keep [ class_ ] ] ) #NEWLINE# remove_these_ones = current_ids . difference ( keep_ids ) #NEWLINE# if remove_these_ones : #NEWLINE# #INDENT# for obj in current : #NEWLINE# #INDENT# if ( obj . pk in remove_these_ones ) : #NEWLINE# #INDENT# obj . delete ( ) #NEWLINE# if ( verbosity >= 2 ) : #NEWLINE# #INDENT# print ( ( 'Deleted object: %s' % six . u ( obj ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( verbosity > 0 ) and remove_these_ones ) : #NEWLINE# #INDENT# num_deleted = len ( remove_these_ones ) #NEWLINE# if ( num_deleted > 1 ) : #NEWLINE# #INDENT# type_deleted = six . u ( class_ . _meta . verbose_name_plural ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# type_deleted = six . u ( class_ . _meta . verbose_name ) #NEWLINE# #UNINDENT# print ( ( 'Deleted %s %s' % ( str ( num_deleted ) , num_deleted ) ) )