Featured post
python - Where to place the call to a external API that has a dependency on a Model? -
suppose have django app named "blog".
there's model called post
, have external api call returns list of popular posts in given time, e.g., google analytics api.
my question is: expected place should place code makes call external api, parses id each post, query database , sort list of models accordingly?
i don't think should live in manager
or in templatetag
. tips or suggestions?
thanks in advance!
edit: desired result might need in several places across project, if place code in view, i'll have duplication.
it should done in view, or better, if view code getting cluttered, put in helper module.
import util def view(request): util.process_post_rankings(request.user.id) # ... write additional logic , render template
however, cautious relying on external apis render page user. things might go wrong, take awful lot of time, api might not respond etc... better asynchronously javascript, , update page when data ready.
- Get link
- X
- Other Apps
Comments
Post a Comment