How to use APIs with Django, best practice?

Here’s a question from someone who has just started working with the Django framework. I am developing an app for project management and want to generate an update to Slack depending on a project status. I may want to use this piece of code again later. So initially I have a new Django app, but since I’m just pushing to Slack I don’t have any URL routing or models. I can also create a separate .py file with a Slack function within my project management app.

What is the best practice for this?

When do you want these updates pushed?

  • Are they being sent as a result of some other data being updated in your system?

  • Are they being sent periodically? (Like once per day?)

  • Are they to be sent when someone “pushes a button” to send them?

How long does it take for these updates to be sent?

Thanks, for your reply.

  • Are they being sent as a result of some other data being updated in your system? → Yes when the project_phase is updated it will also trigger a function to send a message on Slack. For example: project phase changes from “concept” to “ready to start” or “ready to review” to “project finished”
  • Are they being sent periodically? (Like once per day?) → Once or twice a day
  • Are they to be sent when someone “pushes a button” to send them? → Yes. At the moment to push of a button will update the project_phase data (which is also used in the project dashboard to show the current phase of the project)
  • How long does it take for these updates to be sent? → I am not quite sure I understand your question but I want to trigger “Send message to Slack” function immediately after project phase data is updated.

I was asking how long your process takes to run. I don’t know if your “Slack update” can complete in 1 second, 10 seconds, 100 seconds or 1000 seconds or more. Each one of those possibilities has implications regarding the best way to handle this.

Assuming it fits into the 10 seconds or less category, I would just do the update in the view that updates the project phase. (I may physically place the code in a different function - I wouldn’t necessary include it directly in the view, but I would call that function from the view.) I don’t see a reason to do anything else.