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.

  • 2
    Are there any details about this third-party module? Perhaps you can create not the model itself, but something similar to the model that the third-party module considers to be the real model) - andreymal
  • You can create a model, just do not save it to the database. Ie without create() or save() . Example: obj = MyModel(title='title', **data) . The only thing is - pk, and therefore the id will be None - zvadym
  • Uses upgraded django material module. “Under the hood” everything is set to display models for CRUD. To the second comment: is it possible in more detail about your method? - anderson

1 answer 1

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