Using the Models from two Different Projects in a single script

6 views
Skip to first unread message

Glen D souza

unread,
Jan 15, 2019, 4:35:22 AM1/15/19
to django...@googlegroups.com
Hi,

I have two different django projects which each project having different model

Lets say projects to be p1 and p2


Now i have to populate the data from p1 model to a model in p2 ( note p1 and p2 models are different, i just have to use some data from p1 model to move to p2)


Now in order to write the script i have to initialise two different django projects, something like


os.environ.setdefault('DJANGO_SETTINGS_MODULE', "p1.settings")
django.setup()


settings.configure("p2.settings", DEBUG=True)
django.setup()


So i was wondering, is this even possible? and is there any other way


Thanks

Michal Petrucha

unread,
Jan 15, 2019, 5:04:28 AM1/15/19
to django...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hi Glen,

This won't work – Django uses a whole lot of global state to keep
track of all the settings, model registries, and so on.

I'd suggest an alternative approach, where you'd use a management
command to export the relevant data from one project (either just
dumpdata, or write your own, more specialized version), and then use
another management command in the other project to import the exported
data (again, either write your own custom importer, or use loaddata,
depending on whether you need to transform it in any way).

Good luck,

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJcPbANAAoJEHA7T/IPM/klSMIQALnCiWUeVCvKvjVnrk6bboYX
abN8NrPjO/rEwVzqMnxw1V5wZvJ12SgK/hQMiiaO+LKMsbx0D8PSWTlZdPRzBWOi
asXnlxKdrEy/2zT7ohW0DGdl8mwltqIdkqtbAZl4T9/+gOwUiFIdvfw1SKX/Zbrx
rTXBKb/cwixUymfRPmdX0ML4d9NTQ4JD4N2RW1OKtMrn2PpfdW9nqtiukFC16ExX
8Zbow6SQHL5m2VfR/FJIdXY2ueG7RRm6TPrrHUF6ww3NIKBx1grUHw6vcyIW3ueb
YE0dDIhK0Xcj0zxwjumxjKG/Snzlrwc2TKtOM0syf3FXdgv4IWnP0iqj6i8R9hwM
F5x+4WsFrBbd6hLlNWXGmcwa5VzdxHSI0fZzVbtQI5gfMKVyk0byWdHIBlgNhBd6
SzwkGN2AgK+++cMwwGNKpiuo27EOS/ilHD7oLBTDSXcKFJ7UU9Unp56at+2mmd82
SjZsoDnoYoeOiuJ+Z6TMfvidvKrUJsuYqqZxWwlrUPLz1zWAyyWRdAq1n1fiZh3K
i8mr/n/QD64Jaq9KNZ+CU+/65Jicxg0bAtuvUuDrBUIirua9RJ+XEFTmphCWIobj
gBt5NPoR4ZkODukFG2N8IY3xxc9qEoZynTrhIxxpxcZJIdv2PoljsTnOk9BkUCYb
l+rHw0rgU2BZJkAd7AYg
=cOhG
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages