Import Export Models

Hello! I want to create an import/export system in Django. I have multiple instances of the same app, and I want to allow users to add new data from one instance to another using CSV or Excel files. The problem arises when I have models that have a foreign key to another model, and perhaps that object isn’t already in the database. Also, maybe the primary key doesn’t correspond. The flow is as follows: exporting from one instance and importing to another. What do you recommend?

You can use custom management commands or standalone python scripts.

You could take a look at how django-import-export · PyPI does it.

1 Like

I recommend using “natural keys” for identifying which objects are already in the database. Django has a native support for that.

1 Like