V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lbfeng
V2EX  ›  Python

Flask-sqlalchemy hybrid_property 能被 query 吗?

  •  
  •   lbfeng · 2016-11-09 02:07:51 +08:00 · 1859 次点击
    这是一个创建于 2725 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有 3 个 class Class, Student, Homework 。 Class 对 Student 一对多, Student 对 Homework 一对多。

    在 Class 中有 hybrid_property 返回 Class 中的 Homework 并集.

    @hybrid_property
    def homeworks(self):
    	return set([student.homeworks.all() for student in self.students.all()])
        
    @homeworks.expression
    def homeworks(cls):
        return select([distinct(Homework)]).where(and_(Student.class_id == cls.id, Student.homework_id == Homework.id)).as_scalar()
    

    现在想返回某个 Class 的 deadline 在 2016.11.11 的所有 homework 。

    one_class.homeworks.filter(Homework.deadline == traget_date).all()
    

    产生错误 homeworks Set object 没有 filter 方法。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1021 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:07 · PVG 06:07 · LAX 15:07 · JFK 18:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.