P
P
pcdesign2015-08-03 14:58:20
ORM
pcdesign, 2015-08-03 14:58:20

What about requests that are repeated in multiple routes?

For example, here is a query:

News.query.filter_by(n_active=1).order_by(News.n_id.desc()).all()


It is used in 3 routes.
/
/news
/admin/editnews/

What is the right way to deal with repeated requests?
Move it to a separate function? Or maybe in a separate file and wrapped in a class?
Advise, plz, what is the right way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-08-03
@pcdesign

class News(db.Model):
  ...
  @classmethod
  get_active_news(cls):
    return cls.query.filter_by(n_active=1).order_by(News.n_id.desc()).all()

Then use:
active_news = News.get_active_news()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question