Is it possible to create a pseudo model with data in Django? There are data obtained by third-party scripts (always different, it does not make sense to store them) and for the correct display on the page I need to convert this data into a model with this same data.
Found in the documentation an example of creating only a model, but without data. I understand that you can simply throw the data on the page through the context, but this method is not suitable because it uses a third-party module for rendering pages that have input data for the model.
|
1 answer
I suggest to use the database (at least sqlite in /tmp/mini-shared-db.sqlite ) and bring the work with scripts into a separate service.
Use SIGUSR1 or another signal (dbus?) To run the script on demand.
This service can be started with all the features of django using the manage.py commands .
Running scripts from the django handler can cause errors associated with file locks, devices (or whatever you have behind the scripts), overwriting intermediate variables and with other race.
- It was decided to go approximately along the proposed path. Those. We decided to use the database table as a cache in the project and update the data in it through a script on demand on the client side. It remains to figure out how this can be finished with celery, so that long execution commands take place in the background process - anderson
|
create()orsave(). Example:obj = MyModel(title='title', **data). The only thing is - pk, and therefore the id will beNone- zvadym