I had a similar problem where I needed to get read-only access to a
Django model from a system script. I'm not sure what information
you're trying to pull, but in my own case I just wrote a view that
dumped the info I needed and write a simple authentication function
that tested the visitor's IP address to make sure it was coming from a
tuple of known and trusted static IP addresses else return a 404.

Of course, this method doesn't retain the model, but if you just need
to run a simple read-only query rather than the entire model, you
could use this method with one of the serializers to dump as XML or
JSON or just write a few lines to dump the query results as CSV then
return as "text/plain" for further processing.

Russ B.

On Nov 4, 3:28 pm, 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...
>
> --Cindy

-- 
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.

Reply via email to