<s> """<STR_LIT>""" <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . db import models <EOL> from supertagging . models import SuperTag , SuperTaggedItem <EOL> class ModelTagManager ( models . Manager ) : <EOL> """<STR_LIT>""" <EOL> def get_query_set ( self ) : <EOL> ctype = ContentType . objects . get_for_model ( self . model ) <EOL> return SuperTag . objects . filter ( <EOL> items__content_type__pk = ctype . pk , <EOL> items__ignore = False ) . distinct ( ) <EOL> def cloud ( self , * args , ** kwargs ) : <EOL> return SuperTag . objects . cloud_for_model ( self . model , * args , ** kwargs ) <EOL> def related ( self , tags , * args , ** kwargs ) : <EOL> return SuperTag . objects . related_for_model ( tags , self . model , * args , ** kwargs ) <EOL> def usage ( self , * args , ** kwargs ) : <EOL> return SuperTag . objects . usage_for_model ( self . model , * args , ** kwargs ) <EOL> class ModelTaggedItemManager ( models . Manager ) : <EOL> """<STR_LIT>""" <EOL> def related_to ( self , obj , queryset = None , num = None ) : <EOL> if queryset is None : <EOL> return SuperTaggedItem . objects . get_related ( obj , self . model , num = num ) <EOL> else : <EOL> return SuperTaggedItem . objects . get_related ( obj , queryset , num = num ) <EOL> def with_all ( self , tags , queryset = None ) : <EOL> if queryset is None : <EOL> return SuperTaggedItem . objects . get_by_model ( self . model , tags ) <EOL> else : <EOL> return SuperTaggedItem . objects . get_by_model ( queryset , tags ) <EOL> def with_any ( self , tags , queryset = None ) : <EOL> if queryset is None : <EOL> return SuperTaggedItem . objects . get_union_by_model ( self . model , tags ) <EOL> else : <EOL> return SuperTaggedItem . objects . get_union_by_model ( queryset , tags ) <EOL> class TagDescriptor ( object ) : <EOL> """<STR_LIT>""" <EOL> def __get__ ( self , instance , owner ) : <EOL> if not instance : <EOL> tag_manager = ModelTagManager ( ) <EOL> tag_manager . model = owner <EOL> return tag_manager <EOL> else : <EOL> return SuperTag . objects . get_for_object ( instance ) <EOL> def __set__ ( self , instance , value ) : <EOL> raise NotImplementedError <EOL> def __delete__ ( self , instance ) : <EOL> raise NotImplementedError </s>
