Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a column with an @property that hits an external service #1727

Open
dwwoelfel opened this issue Oct 12, 2018 · 1 comment
Open

Create a column with an @property that hits an external service #1727

dwwoelfel opened this issue Oct 12, 2018 · 1 comment

Comments

@dwwoelfel
Copy link

I'm trying to add a column that pulls in data about my users from an external API. For example, I want to have a column that shows whether they're subscribed to a mailing list in Mailchimp.

I can easily add the column using @property, like this:

class User(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  email = db.Column(db.String(255))
  @property
  def subscribed_to_list(self):
    requests.get("https://mailchimp.com/is_subscribed").text

With that approach every pageload takes multiple seconds as an API request is made for each row. Is there some way to send the computed property asynchronously?

I found form_ajax_refs, but I need something that works on the list page.

@zaniar
Copy link

zaniar commented Oct 13, 2018

Try to override ModelView's get_list() method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants