小编Joe*_* JJ的帖子

从至少有2条评论的课程开始,选择评论最多的课程

我正在使用Flask-SQLAlchemy和PostgreSQL.我有以下两种型号:

class Course(db.Model):
    id = db.Column(db.Integer, primary_key = True )
    course_name =db.Column(db.String(120))
    course_description = db.Column(db.Text)
    course_reviews = db.relationship('Review', backref ='course', lazy ='dynamic')

class Review(db.Model):
    __table_args__ = ( db.UniqueConstraint('course_id', 'user_id'), { } )
    id = db.Column(db.Integer, primary_key = True )
    review_date = db.Column(db.DateTime)#default=db.func.now()
    review_comment = db.Column(db.Text)
    rating = db.Column(db.SmallInteger)
    course_id = db.Column(db.Integer, db.ForeignKey('course.id') )
    user_id = db.Column(db.Integer, db.ForeignKey('user.id') )
Run Code Online (Sandbox Code Playgroud)

我想从至少两篇评论中选择最受评论的课程.以下SQLAlchemy查询适用于SQlite:

most_rated_courses = db.session.query(models.Review, func.count(models.Review.course_id)).group_by(models.Review.course_id).\
          having(func.count(models.Review.course_id) >1) \   .order_by(func.count(models.Review.course_id).desc()).all()
Run Code Online (Sandbox Code Playgroud)

但是当我在生产中切换到PostgreSQL时,它给了我以下错误:

ProgrammingError: (ProgrammingError) column "review.id" must appear in the GROUP BY clause or …
Run Code Online (Sandbox Code Playgroud)

postgresql sqlalchemy flask-sqlalchemy

3
推荐指数
1
解决办法
540
查看次数

卸载anaconda后出现Ipython内核错误

我在ubuntu 14.04上.我正在运行anaconda,我使用conda命令(根据这篇文章)使ipython笔记本中的python 2和python 3都可用.但我刚刚卸载了anaconda并在virtualenv中单独安装了ipython,jupyter和notebook.现在,当我尝试创建一个新笔记本时,我收到以下错误.正如你在最后一行中看到的那样,它似乎仍然指的是用anaconda创建的内核,因为我卸载了anaconda后显然不再存在.

有人可以帮我解决这个问题吗?非常感谢.

 Traceback (most recent call last):
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/notebook/base/handlers.py", line 458, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/tornado/gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/notebook/services/sessions/handlers.py", line 58, in post
    sm.create_session(path=path, kernel_name=kernel_name))
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/home/joe/.virtualenvs/crissp/lib/python3.4/site-packages/tornado/concurrent.py", line 232, in result …
Run Code Online (Sandbox Code Playgroud)

ipython anaconda jupyter jupyter-notebook

1
推荐指数
1
解决办法
1794
查看次数