On Fri, Nov 5, 2010 at 6:28 AM, Cindy Moore <ctmoore.u...@gmail.com> wrote: > Hi, all. I'm trying to figure out how to do this. I have two django > projects, on different servers (though I have control over each). > > On one of the projects (call this the primary project), I would like > to *read* the info from the other (secondary) project. No need to > modify the secondary project's info, I just want to scrape its info at > will. > > Now, I could just reach through the mysql databases and do direct > queries, but I'd really rather use the other project's module > definitions to access the information. > > I've set up a second database in settings.py of my primary project, > eg > > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.mysql', > 'NAME': 'primary', > 'USER': 'sysadmin', > 'PASSWORD': 'xxx', > 'HOST': '127.0.0.1', > 'PORT': '', > }, > # to examine the models on secondary > 'dcswitchinfo': { > 'ENGINE': 'django.db.backends.mysql', > 'NAME': 'secondary', > 'USER': 'sysadmin', > 'PASSWORD': 'xxx', > 'HOST': 'secondary.com', > 'PORT': '', > } > } > > Now, it seems like I'm going to have to copy the models.py from > secondary over to the primary's directory? I cant' see any other way > of being able to import the relevant info when I want to write > something up in the views.py. That raises the question of what else > besides models.py I'd need to copy over from the secondary project. > Ideally I could jsut copy that over, and set up the DATABASE_ROUTERS > to split out where it looks for each model. (Or just do it manually > using the 'using' method when referencing secondary's classes.) > > Is this a reasonable approach, or should I just bite the bullet and do > raw sql commands to pull the info from secondary's mysql db? Has > anyone done this? I googled around a fair bit, but all the extra > database examples kept the django project as the central hub, spinning > out the websites or the databases, but not instances of django > installations...
You shouldn't need to copy anything, models.py or otherwise. It's just a matter of setting up your PYTHONPATH. Yes, Django's tutorial suggests that you use a 'project' as a hub, but that not a requirement. A Django application is just a Python module that happens to contain a models.py file. As long as that app/module is on your PYTHONPATH, you can import and use it in your project. So - put the apps from project 2 on your PYTHONPATH, and reference them in the INSTALLED_APPS for project 1, and you should be able to import those models, use them to query your secondary database, and/or use a router to direct query traffic as required. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.