<s> import datetime <EOL> import hashlib <EOL> from django . conf import settings <EOL> from django . core import validators <EOL> from django . db import models , router <EOL> from django . db . models import query <EOL> from ticketing . models import Ticket <EOL> class QuerySet ( query . QuerySet ) : <EOL> @ property <EOL> def db ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _for_write : <EOL> return self . _db <EOL> return self . _db or router . db_for_read ( self . model ) <EOL> class Manager ( models . Manager ) : <EOL> def get_query_set ( self ) : <EOL> return QuerySet ( self . model , using = self . _db ) <EOL> @ property <EOL> def db ( self ) : <EOL> return None <EOL> class Review ( models . Model ) : <EOL> author_id = models . IntegerField ( ) <EOL> product_id = models . IntegerField ( ) <EOL> rating = models . PositiveIntegerField ( null = True , validators = [ <EOL> validators . MaxValueValidator ( <NUM_LIT:5> ) , validators . MinValueValidator ( <NUM_LIT:1> ) ] ) <EOL> text = models . TextField ( ) <EOL> created = models . DateTimeField ( default = datetime . datetime . now ) <EOL> id = models . IntegerField ( default = Ticket . objects . new , primary_key = True ) <EOL> objects = Manager ( ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . author_id , <EOL> self . product_id , self . created . strftime ( "<STR_LIT>" ) ) <EOL> def get_db_num ( self ) : <EOL> """<STR_LIT>""" <EOL> return get_db_for_id ( self . id ) <EOL> def get_db_for_id ( id_value ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:1> + ( int ( hashlib . md5 ( str ( id_value ) ) . hexdigest ( ) , <NUM_LIT:16> ) % <EOL> settings . CLUSTER_SIZE ) </s>
