Search code examples
phpdjangoormdata-transfer

Using php to write into django ORM


I use a php library where something similar does not exist for python / django. So I wrote a php script using the library and now I would like to use the resulting data in Django.

I can think of two approaches to get the php data into Django:

  1. I could use php to write into the mysql database that I use for the Django ORM.
  2. I could write my php results into a local file and trigger Django by calling a view via http or via a management command to import the data.

Is there a commonly accepted way of doing such things?


Solution

  • If you want to use Django ORM ( means you are using a Django in somewhere in the app), then the approaches you are given is ok and acceptable. But if all you want is an ORM, then why not try a PHP one like this ?

    Betterway for two techs can communicate is using any IPC mechanisms like Process/TCP/Http direct (or RPC).

    or

    $command = "python manage.py storedata" // custom manage command
    $output = shell_exec($command); // or $output = `python manage.py storedata`
    

    But keeping two codebases, in future will become unmaintainable, so use any PHP native solution.