1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
from datetime import datetime
class Link(object):
def __init__(self, username, url, title):
self.username = username
self.url = url
self.title = title
self.time = datetime.utcnow()
self.id = hex(hash(tuple([username, url, title, self.time])))[2:]
self.comments = []
def __repr__(self):
return '<%s %r>' % (type(self).__name__, self.title)
def add_comment(self, username, content):
comment = Comment(username, content)
self.comments.append(comment)
return comment
class Comment(object):
def __init__(self, username, content):
self.username = username
self.content = content
self.time = datetime.utcnow()
def __repr__(self):
return '<%s by %r>' % (type(self).__name__, self.username)
|