<s> from django . db import connection <EOL> from django . conf import settings <EOL> from django . db import models <EOL> try : <EOL> from django . contrib . contenttypes . fields import GenericForeignKey , GenericRelation <EOL> except ImportError : <EOL> from django . contrib . contenttypes . generic import GenericForeignKey , GenericRelation <EOL> from django . contrib import contenttypes <EOL> from django . core . cache import cache <EOL> from denorm . fields import SumField <EOL> from denorm import denormalized , depend_on_related , CountField , CacheKeyField , cached <EOL> settings . DENORM_MODEL = '<STR_LIT>' <EOL> class FailingTriggersModelA ( models . Model ) : <EOL> order = models . SmallIntegerField ( default = <NUM_LIT:0> ) <EOL> SomeWeirdName = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> class FailingTriggersModelB ( models . Model ) : <EOL> a = models . ForeignKey ( FailingTriggersModelA ) <EOL> @ denormalized ( models . TextField ) <EOL> @ depend_on_related ( FailingTriggersModelA ) <EOL> def SomeWeirdName ( self ) : <EOL> return self . a . SomeWeirdName <EOL> class CachedModelA ( models . Model ) : <EOL> b = models . ForeignKey ( '<STR_LIT>' ) <EOL> @ cached ( cache ) <EOL> @ depend_on_related ( '<STR_LIT>' ) <EOL> def cached_data ( self ) : <EOL> return { <EOL> '<STR_LIT>' : self . b . data . upper ( ) , <EOL> '<STR_LIT>' : self . b . data . lower ( ) , <EOL> } <EOL> class CachedModelB ( models . Model ) : <EOL> data = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> class AbstractDenormModel ( models . Model ) : <EOL> text = models . TextField ( ) <EOL> @ denormalized ( models . TextField ) <EOL> def ham ( self ) : <EOL> return u"<STR_LIT>" % self . text <EOL> class Meta : <EOL> abstract = True <EOL> app_label = '<STR_LIT>' <EOL> class DenormModel ( AbstractDenormModel ) : <EOL> @ denormalized ( models . TextField ) <EOL> def spam ( self ) : <EOL> return u"<STR_LIT>" % self . text <EOL> class Meta ( AbstractDenormModel . Meta ) : <EOL> swappable = '<STR_LIT>' <EOL> class RealDenormModel ( AbstractDenormModel ) : <EOL> @ denormalized ( models . TextField ) <EOL> def eggs ( self ) : <EOL> return u"<STR_LIT>" % self . text <EOL> class Meta ( AbstractDenormModel . Meta ) : <EOL> pass <EOL> class Tag ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> content_type = models . ForeignKey ( contenttypes . models . ContentType ) <EOL> object_id = models . PositiveIntegerField ( ) <EOL> content_object = GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TaggedModel ( models . Model ) : <EOL> tags = GenericRelation ( Tag ) <EOL> @ denormalized ( models . TextField ) <EOL> @ depend_on_related ( Tag ) <EOL> def tags_string ( self ) : <EOL> return '<STR_LIT:U+002CU+0020>' . join ( sorted ( [ t . name for t in self . tags . all ( ) ] ) ) <EOL> class Meta : <EOL> abstract = True <EOL> class Forum ( TaggedModel ) : <EOL> title = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> post_count = CountField ( '<STR_LIT>' ) <EOL> cachekey = CacheKeyField ( ) <EOL> cachekey . depend_on_related ( '<STR_LIT>' ) <EOL> @ denormalized ( models . CharField , max_length = <NUM_LIT:255> ) <EOL> @ depend_on_related ( '<STR_LIT>' ) <EOL> def author_names ( self ) : <EOL> return '<STR_LIT:U+002CU+0020>' . join ( ( m . author_name for m in self . post_set . all ( ) ) ) <EOL> @ denormalized ( models . ManyToManyField , '<STR_LIT>' , blank = True ) <EOL> @ depend_on_related ( '<STR_LIT>' ) <EOL> def authors ( self ) : <EOL> return [ m . author for m in self . post_set . all ( ) if m . author ] <EOL> parent_forum = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) <EOL> @ denormalized ( models . TextField ) <EOL> @ depend_on_related ( '<STR_LIT>' , type = '<STR_LIT>' ) <EOL> def path ( self ) : <EOL> if self . parent_forum : <EOL> return self . parent_forum . path + self . title + '<STR_LIT:/>' <EOL> else : <EOL> return '<STR_LIT:/>' + self . title + '<STR_LIT:/>' <EOL> class Post ( TaggedModel ) : <EOL> forum = models . ForeignKey ( Forum , blank = True , null = True ) <EOL> author = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True ) <EOL> response_to = models . ForeignKey ( '<STR_LIT>' , blank = True , null = True , related_name = '<STR_LIT>' ) <EOL> title = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> @ denormalized ( models . CharField , max_length = <NUM_LIT:255> ) <EOL> @ depend_on_related ( Forum ) <EOL> def forum_title ( self ) : <EOL> return self . forum . title <EOL> @ denormalized ( models . CharField , max_length = <NUM_LIT:255> ) <EOL> @ depend_on_related ( '<STR_LIT>' , foreign_key = "<STR_LIT>" ) <EOL> def author_name ( self ) : <EOL> if self . author : <EOL> return self . author . name <EOL> else : <EOL> return '<STR_LIT>' <EOL> @ denormalized ( models . PositiveIntegerField ) <EOL> @ depend_on_related ( '<STR_LIT>' , type = '<STR_LIT>' ) <EOL> def response_count ( self ) : <EOL> if not self . pk : <EOL> return <NUM_LIT:0> <EOL> rcount = self . responses . count ( ) <EOL> rcount += sum ( ( x . response_count for x in self . responses . all ( ) ) ) <EOL> return rcount <EOL> class PostExtend ( models . Model ) : <EOL> post = models . OneToOneField ( '<STR_LIT>' ) <EOL> @ denormalized ( models . CharField , max_length = <NUM_LIT:255> ) <EOL> @ depend_on_related ( '<STR_LIT>' ) <EOL> def author_name ( self ) : <EOL> return post . author . name <EOL> class Attachment ( models . Model ) : <EOL> forum_as_object = False <EOL> post = models . ForeignKey ( Post , blank = True , null = True ) <EOL> cachekey = CacheKeyField ( ) <EOL> cachekey . depend_on_related ( '<STR_LIT>' ) <EOL> @ denormalized ( models . ForeignKey , Forum , blank = True , null = True ) <EOL> @ depend_on_related ( Post ) <EOL> def forum ( self ) : <EOL> if self . post and self . post . forum : <EOL> if self . forum_as_object : <EOL> return self . post . forum <EOL> else : <EOL> return self . post . forum . pk <EOL> return None <EOL> class Member ( models . Model ) : <EOL> first_name = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> name = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> bookmarks = models . ManyToManyField ( '<STR_LIT>' , blank = True ) <EOL> cachekey = CacheKeyField ( ) <EOL> cachekey . depend_on_related ( '<STR_LIT>' , foreign_key = '<STR_LIT>' ) <EOL> @ denormalized ( models . CharField , max_length = <NUM_LIT:255> ) <EOL> def full_name ( self ) : <EOL> return u"<STR_LIT>" % ( self . first_name , self . name ) <EOL> @ denormalized ( models . TextField , null = True , blank = True ) <EOL> @ depend_on_related ( '<STR_LIT>' , foreign_key = "<STR_LIT>" ) <EOL> def bookmark_titles ( self ) : <EOL> if self . id : <EOL> return '<STR_LIT:\n>' . join ( [ p . title for p in self . bookmarks . all ( ) ] ) <EOL> class SkipPost ( models . Model ) : <EOL> text = models . TextField ( ) <EOL> class CallCounter ( models . Model ) : <EOL> @ denormalized ( models . IntegerField ) <EOL> def called_count ( self ) : <EOL> if not self . called_count : <EOL> return <NUM_LIT:1> <EOL> return self . called_count + <NUM_LIT:1> <EOL> class CallCounterProxy ( CallCounter ) : <EOL> class Meta : <EOL> proxy = True <EOL> class SkipComment ( models . Model ) : <EOL> post = models . ForeignKey ( SkipPost ) <EOL> text = models . TextField ( ) <EOL> created_on = models . DateTimeField ( auto_now_add = True ) <EOL> updated_on = models . DateTimeField ( auto_now = True , null = True , blank = True ) <EOL> class Meta : <EOL> abstract = True <EOL> class SkipCommentWithoutSkip ( SkipComment ) : <EOL> @ denormalized ( models . TextField ) <EOL> @ depend_on_related ( SkipPost ) <EOL> def post_text ( self ) : <EOL> return self . post . text <EOL> class SkipCommentWithSkip ( SkipComment ) : <EOL> @ denormalized ( models . TextField , skip = ( '<STR_LIT>' , ) ) <EOL> @ depend_on_related ( SkipPost ) <EOL> def post_text ( self ) : <EOL> return self . post . text <EOL> class SkipCommentWithAttributeSkip ( SkipComment ) : <EOL> @ denormalized ( models . TextField ) <EOL> @ depend_on_related ( SkipPost ) <EOL> def post_text ( self ) : <EOL> return self . post . text <EOL> denorm_always_skip = ( '<STR_LIT>' , ) <EOL> if connection . vendor != "<STR_LIT>" : <EOL> class FilterSumModel ( models . Model ) : <EOL> active_item_sum = SumField ( '<STR_LIT>' , field = '<STR_LIT>' , filter = { '<STR_LIT>' : <NUM_LIT> } ) <EOL> class FilterSumItem ( models . Model ) : <EOL> parent = models . ForeignKey ( FilterSumModel , related_name = '<STR_LIT>' ) <EOL> age = models . IntegerField ( default = <NUM_LIT> ) <EOL> active_item_count = models . PositiveIntegerField ( default = False ) <EOL> class FilterCountModel ( models . Model ) : <EOL> active_item_count = CountField ( '<STR_LIT>' , filter = { '<STR_LIT>' : True } , exclude = { '<STR_LIT:text>' : '<STR_LIT>' } ) <EOL> class FilterCountItem ( models . Model ) : <EOL> parent = models . ForeignKey ( FilterCountModel , related_name = '<STR_LIT>' ) <EOL> active = models . BooleanField ( default = False ) <EOL> text = models . CharField ( max_length = <NUM_LIT:10> , default = '<STR_LIT>' ) </s>
