<s> """<STR_LIT>""" <EOL> import sys <EOL> import datetime <EOL> from uuid import uuid4 <EOL> from sqlalchemy import Column , String , Integer , ForeignKey <EOL> from sqlalchemy . dialects . postgresql import UUID <EOL> from sqlalchemy . orm import relationship <EOL> from websauna . system import Initializer <EOL> from websauna . system . model . meta import Base <EOL> from websauna . system . model . columns import UTCDateTime <EOL> from websauna . utils . time import now <EOL> class Question ( Base ) : <EOL> __tablename__ = "<STR_LIT>" <EOL> id = Column ( Integer , autoincrement = True , primary_key = True ) <EOL> uuid = Column ( UUID ( as_uuid = True ) , default = uuid4 ) <EOL> question_text = Column ( String ( <NUM_LIT> ) , default = None ) <EOL> published_at = Column ( UTCDateTime , default = None ) <EOL> choices = relationship ( "<STR_LIT>" , <EOL> back_populates = "<STR_LIT>" , <EOL> lazy = "<STR_LIT>" , <EOL> cascade = "<STR_LIT>" , <EOL> single_parent = True ) <EOL> def is_recent ( self ) : <EOL> return self . published_at >= now ( ) - datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . id , self . question_text ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . question_text <EOL> class Choice ( Base ) : <EOL> __tablename__ = "<STR_LIT>" <EOL> id = Column ( Integer , autoincrement = True , primary_key = True ) <EOL> uuid = Column ( UUID ( as_uuid = True ) , default = uuid4 ) <EOL> choice_text = Column ( String ( <NUM_LIT> ) , default = None ) <EOL> votes = Column ( Integer , default = <NUM_LIT:0> ) <EOL> question_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> question = relationship ( "<STR_LIT>" , back_populates = "<STR_LIT>" , uselist = False ) <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" . format ( self . id , self . choice_text ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . choice_text <EOL> from websauna . system . admin . modeladmin import model_admin <EOL> from websauna . system . admin . modeladmin import ModelAdmin <EOL> @ model_admin ( traverse_id = "<STR_LIT>" ) <EOL> class QuestionAdmin ( ModelAdmin ) : <EOL> title = "<STR_LIT>" <EOL> singular_name = "<STR_LIT>" <EOL> plural_name = "<STR_LIT>" <EOL> model = Question <EOL> class Resource ( ModelAdmin . Resource ) : <EOL> def get_title ( self ) : <EOL> return self . get_object ( ) . question_text <EOL> @ model_admin ( traverse_id = "<STR_LIT>" ) <EOL> class ChoiceAdmin ( ModelAdmin ) : <EOL> title = "<STR_LIT>" <EOL> singular_name = "<STR_LIT>" <EOL> plural_name = "<STR_LIT>" <EOL> model = Choice <EOL> class Resource ( ModelAdmin . Resource ) : <EOL> def get_title ( self ) : <EOL> return self . get_object ( ) . choice_text <EOL> def main ( global_config , ** settings ) : <EOL> init = Initializer ( global_config ) <EOL> init . run ( ) <EOL> init . config . scan ( sys . modules [ "<STR_LIT>" ] ) <EOL> return init . make_wsgi_app ( ) </s>
