V
V
Vyacheslav Rakhinsky2015-12-27 21:16:24
Django
Vyacheslav Rakhinsky, 2015-12-27 21:16:24

How to make one global instance of a class in Django?

Good evening.
The question is as follows, I need to organize calls (asynchronously, on signals) by sip during certain events in Django.
I've written a small class using the PJSUA library and I need to create one instance of it at application startup so that it's visible everywhere and I can call make_call(...). And it is also necessary that this class could take data from the database using the standard model.
Just in case, I'm not a programmer, I have little experience in writing various scripts in python (only admin tasks) and no OOP . I'm
leaning towards the following
Celery options, but I can't find how to make a task that will start when the app starts and there will be one instance (shared as far as I understand, it is still created by the number of processes)
Use a direct database or some kind of MQ, essentially make your own service.
Well, or as an option to embed flask / twisted there and just manage through a small API
. I would be grateful for useful links to code examples or perhaps a django module that will help me.
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Rakhinsky, 2016-02-22
@rakhinskiy

Perhaps it will come in handy for someone, in my version, the use of Custom management commands
suited me. I wrote a small service that can use all Django models, and in the main model I overridden save() and check connected agents (sip/email/sms/...) and in each call the desired method.
Maybe not quite right, but quite convenient.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question