A
A
anon8112020-07-16 14:03:44
Flask
anon811, 2020-07-16 14:03:44

Building complex database queries?

Hello! Prompt how to unify the interface of obtaining of the data. Now I have this in my model:

class Ticket(db.Model):
.....
    @classmethod
    def get_ticket(cls, **kwargs):
        return Ticket.query.filter_by(**kwargs).first()

    @classmethod
    def get_tickets_with_devices(cls, form):
        return db.session.query(Ticket).outerjoin(Ticket.device).filter(*form.get_query_args()).\
            order_by(Ticket.time_creat.desc())

And I would like one function that could return one object, and a list, and the result of a complex query with joins.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question