#NEWLINE# def get_tag( self , key = None , category = None , obj = None , tagtype = None , global_search = False ) : #NEWLINE# #INDENT# '\n        Return Tag objects by key, by category, by object (it is\n        stored on) or with a combination of those criteria.\n\n        Attrs:\n            key (str, optional): The Tag\'s key to search for\n            category (str, optional): The Tag of the attribute(s)\n                to search for.\n            obj (Object, optional): On which object the Tag to\n                search for is.\n            tagtype (str, optional): One of None (normal tags),\n                "alias" or "permission"\n            global_search (bool, optional): Include all possible tags,\n                not just tags on this object\n\n        Returns:\n            tag (list): The matching Tags.\n\n        ' #NEWLINE# global _Tag #NEWLINE# if ( not _Tag ) : #NEWLINE# #INDENT# from evennia.typeclasses.models import Tag as _Tag #NEWLINE# #UNINDENT# if global_search : #NEWLINE# #INDENT# query = [ ( 'db_tagtype' , self ) ] #NEWLINE# if obj : #NEWLINE# #INDENT# query . append ( ( 'id' , obj . id ) ) #NEWLINE# #UNINDENT# if key : #NEWLINE# #INDENT# query . append ( ( 'db_key' , key ) ) #NEWLINE# #UNINDENT# if category : #NEWLINE# #INDENT# query . append ( ( 'db_category' , category ) ) #NEWLINE# #UNINDENT# return _Tag . objects . filter ( ** dict ( query ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query = [ ( 'tag__db_tagtype' , tagtype ) ] #NEWLINE# if obj : #NEWLINE# #INDENT# query . append ( ( ( '%s__id' % self . model . __name__ . lower ( ) ) , obj . id ) ) #NEWLINE# #UNINDENT# if key : #NEWLINE# #INDENT# query . append ( ( 'tag__db_key' , key ) ) #NEWLINE# #UNINDENT# if category : #NEWLINE# #INDENT# query . append ( ( 'tag__db_category' , category ) ) #NEWLINE# #UNINDENT# return [ th . tag for th in self . model . db_tags . through . objects . filter ( ** dict ( query ) ) ]