<s> from django . conf import settings <EOL> from django . contrib . contenttypes import generic <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils import timezone <EOL> from django . utils . encoding import python_2_unicode_compatible , force_text <EOL> COMMENT_MAX_LENGTH = getattr ( settings , '<STR_LIT>' , <NUM_LIT> ) <EOL> class CommentManager ( models . Manager ) : <EOL> def for_model ( self , model ) : <EOL> """<STR_LIT>""" <EOL> ct = ContentType . objects . get_for_model ( model ) <EOL> qs = self . get_query_set ( ) . filter ( content_type = ct ) <EOL> if isinstance ( model , models . Model ) : <EOL> qs = qs . filter ( object_pk = force_text ( model . _get_pk_val ( ) ) ) <EOL> return qs <EOL> @ python_2_unicode_compatible <EOL> class Comment ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> content_type = models . ForeignKey ( <EOL> ContentType , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> related_name = "<STR_LIT>" ) <EOL> object_pk = models . TextField ( _ ( '<STR_LIT>' ) ) <EOL> content_object = generic . GenericForeignKey ( ct_field = "<STR_LIT>" , <EOL> fk_field = "<STR_LIT>" ) <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL , verbose_name = _ ( '<STR_LIT:user>' ) , <EOL> blank = True , null = True , <EOL> related_name = "<STR_LIT>" ) <EOL> comment = models . TextField ( _ ( '<STR_LIT>' ) , max_length = COMMENT_MAX_LENGTH ) <EOL> submit_date = models . DateTimeField ( _ ( '<STR_LIT>' ) , default = None , <EOL> blank = True ) <EOL> objects = CommentManager ( ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> permissions = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . user , self . comment [ : <NUM_LIT:50> ] ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if self . submit_date is None : <EOL> self . submit_date = timezone . now ( ) <EOL> super ( Comment , self ) . save ( * args , ** kwargs ) </s>
