#NEWLINE# def tag_model( cls , admin_cls = None , field_name = 'tags' , sort_tags = False , select_field = False , auto_add_admin_field = True , admin_list_display = True ) : #NEWLINE# #INDENT# '\n    tag_model accepts a number of named parameters:\n\n    admin_cls   If set to a subclass of ModelAdmin, will insert the tag\n                field into the list_display and list_filter fields.\n    field_name  Defaults to "tags", can be used to name your tag field\n                differently.\n    sort_tags   Boolean, defaults to False. If set to True, a pre_save\n                handler will be inserted to sort the tag field alphabetically.\n                This is useful in case you want a canonical representation\n                for a tag collection, as when yo\'re presenting a list of\n                tag combinations (e.g. in an admin filter list).\n    select_field If True, show a multi select instead of the standard\n                CharField for tag entry.\n    auto_add_admin_field If True, attempts to add the tag field to the admin\n                class.\n    ' #NEWLINE# try : #NEWLINE# #INDENT# from tagging.registry import register as tagging_register #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# from tagging import register as tagging_register #NEWLINE# #UNINDENT# cls . add_to_class ( field_name , ( TagSelectField if select_field else TagField ) ( field_name . capitalize ( ) , blank = True ) ) #NEWLINE# try : #NEWLINE# #INDENT# tagging_register ( cls , tag_descriptor_attr = ( 'tagging_' + field_name ) ) #NEWLINE# #UNINDENT# except AlreadyRegistered : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if admin_cls : #NEWLINE# #INDENT# if admin_list_display : #NEWLINE# #INDENT# admin_cls . list_display . append ( field_name ) #NEWLINE# #UNINDENT# admin_cls . list_filter . append ( field_name ) #NEWLINE# if ( auto_add_admin_field and hasattr ( admin_cls , 'add_extension_options' ) ) : #NEWLINE# #INDENT# admin_cls . add_extension_options ( _ ( 'Tagging' ) , { #NEWLINE# #INDENT# 'fields' : ( field_name , ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# if sort_tags : #NEWLINE# #INDENT# pre_save . connect ( pre_save_handler , sender = cls )