refactor(command/database|sondage): update poll model
This commit is contained in:
parent
25f5c5e1f6
commit
d00aadd82f
5 changed files with 23 additions and 16 deletions
|
@ -88,7 +88,7 @@ class Polls(commands.Cog):
|
||||||
icon_url=content.get('author').get('icon_url')
|
icon_url=content.get('author').get('icon_url')
|
||||||
)
|
)
|
||||||
chart_url = URL(chart_base_url + json.dumps(chart_options))
|
chart_url = URL(chart_base_url + json.dumps(chart_options))
|
||||||
e.set_thumbnail(url=chart_url)
|
e.set_thumbnail(url=str(chart_url))
|
||||||
for field in content.get('fields'):
|
for field in content.get('fields'):
|
||||||
e.add_field(
|
e.add_field(
|
||||||
name=field.get('name'),
|
name=field.get('name'),
|
||||||
|
|
|
@ -4,7 +4,7 @@ from sqlalchemy.orm import sessionmaker, session
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.engine = create_engine(config.postgresql)
|
self.engine = create_engine(config.postgresql, echo=True)
|
||||||
|
|
||||||
Session = sessionmaker()
|
Session = sessionmaker()
|
||||||
Session.configure(bind=self.engine)
|
Session.configure(bind=self.engine)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy import Column, Integer, Boolean, BigInteger, JSON
|
from sqlalchemy import Column, Integer, Text, BigInteger, JSON, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
@ -7,15 +8,20 @@ Base = declarative_base()
|
||||||
class Poll(Base):
|
class Poll(Base):
|
||||||
__tablename__ = 'polls'
|
__tablename__ = 'polls'
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
channel_id = Column(BigInteger)
|
channel_id = Column(BigInteger)
|
||||||
message_id = Column(BigInteger)
|
message_id = Column(BigInteger)
|
||||||
content = Column(JSON)
|
|
||||||
is_anonymous = Column(Boolean)
|
|
||||||
responses = Column(JSON, nullable=True)
|
|
||||||
|
|
||||||
def __repr__(self):
|
content = Column(JSON)
|
||||||
return "<Poll(id='%s', channel_id='%s', message_id='%s', poll='%s', " \
|
|
||||||
"is_anonymous='%s', responses='%s')>" % \
|
choice = relationship("Responses")
|
||||||
(self.id, self.channel_id, self.message_id, self.content,
|
|
||||||
self.is_anonymous, self.responses)
|
|
||||||
|
class Responses(Base):
|
||||||
|
__tablename__ = 'responses'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
user = Column(Text)
|
||||||
|
|
||||||
|
poll_id = Column(Integer, ForeignKey('polls.id'))
|
||||||
|
choice = Column(Integer)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"280805240977227776": [
|
"280805240977227776": [
|
||||||
"b!-"
|
"b!"
|
||||||
],
|
],
|
||||||
"303633056944881686": [
|
"303633056944881686": [
|
||||||
"b!-"
|
"b!"
|
||||||
],
|
],
|
||||||
"336642139381301249": [
|
"336642139381301249": [
|
||||||
"b!-"
|
"b!"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -9,4 +9,5 @@ gitpython
|
||||||
requests
|
requests
|
||||||
psutil
|
psutil
|
||||||
bcrypt
|
bcrypt
|
||||||
tcp_latency
|
tcp_latency
|
||||||
|
yarl
|
Loading…
Reference in a new issue