Advertisement
Deerenaros

nothing

Dec 4th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1.  
  2. class Post(db.Model):
  3.     """
  4.     This is a class represents a model-object for a post entity.
  5.         - id (integer): This is a primary key, self creating index by simply counter.
  6.         - title (string): title
  7.         - html (string): content
  8.         - time (datetime): timestamp at creating
  9.         - user_mail (string): this is foreign key that connects with user entity, ondelete param set as RESTRICT for
  10.             restrict deleting, which mean while trying delete a user object, sqlalchemy do not try to delete all
  11.             connected posts with one
  12.     """
  13.     id = db.Column(db.Integer, primary_key=True)
  14.     title = db.Column(db.String(120))
  15.     html = db.Column(db.String(10**6))
  16.     time = db.Column(db.DateTime, default=datetime.now)
  17.     user_mail = db.Column(db.String(36), db.ForeignKey("user.mail", ondelete="RESTRICT"))
  18.  
  19.     @property
  20.     def cut(self):
  21.         return self.html[0:min(400, len(self.html))]
  22.  
  23.     @staticmethod
  24.     def add(**kwargs):
  25.         db.session.add(Post(**kwargs))
  26.  
  27.  
  28. # take a quest about sqlite politics (restrict, cascade)
  29. class User(db.Model):
  30.     """
  31.     This is a class represents a model-object for user entity.
  32.     @type mail: string
  33.     @param mail: This is a primary key, that mean registred user's e-mail.
  34.     @type abut: string
  35.     @param abut: Something about user, that he had wrote at registration.
  36.     @type regd: datetime
  37.     @param regd: Date & time of registration.
  38.     @type brth: datetime
  39.     @param brth: Birthsday.
  40.     @type auth: bool
  41.     @param auth: Is user authenticated.
  42.     @type grup: string
  43.     @param grup: Just a string for group classification. Simply. Hard. Works.
  44.     @type posts: relationship
  45.     @param posts: backref for connecting users with posts.
  46.     """
  47.  
  48.     admin = None
  49.  
  50.     mail = db.Column(db.String(36), primary_key=True)
  51.     abut = db.Column(db.String(10**6))
  52.     regd = db.Column(db.DateTime, default=datetime.now)
  53.     brth = db.Column(db.DateTime)
  54.     pswd = db.Column(db.String(36))
  55.     auth = db.Column(db.Boolean)
  56.     grup = db.Column(db.String(16))
  57.     posts = db.relationship("Post", backref="user", lazy="dynamic")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement