Thank you very much ! It's perfectly working :)

Ed

Le mardi 23 février 2016 16:41:32 UTC+10, Edouard BERTHE a écrit :
>
> Hello everybody !
>
> This is a question I have already posted on Stack Overflow 
> <https://stackoverflow.com/questions/35546853/sqlalchemy-dynamic-customized-collection-class>,
>  
> but as none is answering I decided to post it here too :) However I invite 
> you to go to the Stack Overflow page, as it is maybe more clearly explained 
> than here.
>
> I have a One-To-Many relation between an Article entity and a Post entity 
> (which are the comments on the article).
> Each Post has a date attribute.
> What I would like to do is getting the posts related to an article between 
> two dates directly from this article, using the following syntax :
>
> article.posts[start_date:end_date]
>
> With the "lazy" argument or "relationship", I can do :
>
>     posts = relationship('Post', back_populates='article', lazy='dynamic')
>
> After that, the "posts" attribute isn't a list any longer, but a Query 
> Object, which allows us to do:
>
>     article.posts.filter(Post.date >= start_date, Post.date < 
> end_date).all()
>
> Which is still not exactly what I'm looking for.
>
> I think I have to use the "collection_class" attribute of the 
> relationship, by using a custom Class in which I would override the 
> "__getitem__" method, but I don't know what to write in this function, 
> because we don't have access to the query given by the `relationship` 
> Object !
>
> Does someone have an idea which could help me ?
>
> Thank you !
> Edouard
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to