<s> from django . conf import settings <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> @ python_2_unicode_compatible <EOL> class Category ( models . Model ) : <EOL> name = models . CharField ( _ ( "<STR_LIT:Name>" ) , max_length = <NUM_LIT:255> , unique = True ) <EOL> position = models . IntegerField ( _ ( "<STR_LIT>" ) , default = <NUM_LIT:0> ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> @ python_2_unicode_compatible <EOL> class Forum ( models . Model ) : <EOL> category = models . ForeignKey ( Category , related_name = '<STR_LIT>' ) <EOL> name = models . CharField ( _ ( "<STR_LIT:Name>" ) , max_length = <NUM_LIT:255> ) <EOL> position = models . IntegerField ( _ ( "<STR_LIT>" ) , default = <NUM_LIT:0> ) <EOL> description = models . TextField ( _ ( "<STR_LIT>" ) , blank = True ) <EOL> is_closed = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> def get_latest_topic ( self ) : <EOL> if self . topics . count ( ) > <NUM_LIT:0> : <EOL> return self . topics . all ( ) [ <NUM_LIT:0> ] <EOL> return None <EOL> def get_latest_poster ( self ) : <EOL> latest_topic = self . get_latest_topic ( ) <EOL> if latest_topic : <EOL> return latest_topic . last_post . user . username <EOL> return '<STR_LIT:->' <EOL> def count_topics ( self ) : <EOL> return self . topics . count ( ) <EOL> def count_posts ( self ) : <EOL> count = <NUM_LIT:0> <EOL> for topic in self . topics . all ( ) : <EOL> count += topic . count_posts ( ) <EOL> return count <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> @ python_2_unicode_compatible <EOL> class Topic ( models . Model ) : <EOL> forum = models . ForeignKey ( Forum , related_name = '<STR_LIT>' ) <EOL> name = models . CharField ( _ ( "<STR_LIT:Name>" ) , max_length = <NUM_LIT:255> ) <EOL> last_post = models . ForeignKey ( '<STR_LIT>' , verbose_name = _ ( "<STR_LIT>" ) , related_name = '<STR_LIT>' , blank = True , null = True ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> def count_posts ( self ) : <EOL> return self . posts . count ( ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> @ python_2_unicode_compatible <EOL> class Post ( models . Model ) : <EOL> topic = models . ForeignKey ( Topic , related_name = '<STR_LIT>' ) <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL , related_name = '<STR_LIT>' ) <EOL> created = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now_add = True ) <EOL> updated = models . DateTimeField ( _ ( "<STR_LIT>" ) , auto_now = True ) <EOL> body = models . TextField ( _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> ordering = [ '<STR_LIT>' ] <EOL> def __str__ ( self ) : <EOL> return self . body </s>
