SQLAlchemy Distinct Descending

I have three tables using SQLite & Flask-SQLAlchemy;

- Username
- Password
* joined_group = db.relationship(group, secondary = user_group, backref = "participants")

- GroupId
- GroupPassword
* message = db.relationship('message', backref = "groupid")

- Sender
- Content
* receiver = db.Column(db.String, db.ForeignKey('group.groupid'))

Now user have an access to a "current_user.joined_group" which shows the group objects that the user is currently in.

That group objects have an access to group.message which contains all messages belonging to that group.

Now, I want to create an inbox which queries the current_user.joined_group.messages and only gets the latest message


data = message.query.filter(message.receiver.in_(current_user.joined_group)).all()

This works fine querying all of the message in rooms that the user is joined. However my question here persists.

What could be the possible ways to achieve this functionality?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum