Hi Gregg,

  I've done something similar in the past - had several external databases (MS 
SQL and Oracle) attached to my Django project. These were backends of 
enterprise tools, hundreds of tables each.

  I used the "manage.py inspectdb" command to reverse engineer each "external" 
DB, manually polished models I needed (inspectdb is great but can't always 
perfectly guess foreign key relations or field types). Then I set 
"managed=False" for each model of those external DB's to make sure Django won't 
try to modify them.

  As for writing to those DB's, I had set up my DB routing so that these DB's 
were available only for read, not for wrining. I made sure that my code never 
attempted to write to those DB's. I also never used Django admin for this 
project. 

 YMMV

   Jirka

P.S. You can override the save() of your models in"external DB"  method to do 
nothing
-----Original Message-----
From: Gregg Branquinho <gr...@freightman.com>
Sender: django-users@googlegroups.com
Date: Wed, 24 Oct 2012 21:43:01 
To: <django-users@googlegroups.com>
Reply-To: django-users@googlegroups.com
Subject: Re: Connecting to external databases from Views.py

Hi Russel,

First off thank you for the suggestion, I am going to give it a whirl and 
see how it works out.. I have a couple of concerns about the pricing 
database it the
* it is on  mssql and the data is spread accross 3 database on the same 
server so the query would have to be cross database.. which also pose's a 
problem.
* the db's have like 300 table each..

Before you answer I wat thinking of accessing the database on the view 
*yuck* via pyodbc.

after your answer I have a couple more questions ?

Is is possible to override how a model is loaded from the database with raw 
sql and then overide the save and update methods to do nothing ? I have 
look at ovveriding __init__ but all recommendation are against it, but 
since I am not saving would it make any difference ?

Thanks very much for you previous answer as I feel it is pushing me towards 
a better solution

Kind regards
Gregg










On Thursday, 25 October 2012 02:49:49 UTC+2, Russell Keith-Magee wrote:
>
> Hi Gregg,
>
> Is there any reason you can't treat this as a mutliple-database 
> configuration?
>
> https://docs.djangoproject.com/en/dev/topics/db/multi-db/
>
> Django allows you to specify more than one database, and then direct 
> queries at specific databases. So, you have your "main" django database for 
> your own application, but you set up a connection to your "other" database 
> to access the pricing report.
>
> You'll need to write some Django model wrappers for the data in the 
> 'other' database -- inspectdb can help with that -- but once you've done 
> that, you'll be able to query the 'other' database as if it were a set of 
> normal Django models.
>
> Yours,
> Russ Magee %-)
>
> On Thu, Oct 25, 2012 at 4:43 AM, Gregg Branquinho 
> <gr...@freightman.com<javascript:>
> > wrote:
>
>> Hi guys I am new to django and have built my first application that is 
>> being used to track and compare pricelists from vendors and it is working 
>> awesomly, I have had a request for a new feature and I am alittle boggled 
>> at to how I am going to do it..
>>
>> Basically I wasnt to create a view which returns read only data(a report) 
>> from an external database which is not the django database. I dont want to 
>> copy the data to the django database and use a models as then concurreny 
>> become an issue
>>
>> What would you guys recommened..
>>
>> I was thinking on implenting a odbc connection from the views.py method 
>> called for my url ? but database call from the view , sound a abit dodgy.
>>
>> Any ideas ?
>>
>>
>>
>>
>>
>> Email Disclaimer <http://www.freightman.com/Legal/EmailDisclaimer> | Quote 
>> Disclaimer <http://www.freightman.com//Legal/QuoteDisclaimer> | All 
>> business is undertaken subject to our General Trading Conditions, a copy of 
>> which is available on request and on our website 
>> www.freightman.com<http://www.freightman.com/Legal/TradingTerms> 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/ewQAAfxJlJ4J.
>> To post to this group, send email to django...@googlegroups.com<javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com <javascript:>.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
-- 
Email Disclaimer <http://www.freightman.com/Legal/EmailDisclaimer> | Quote 
Disclaimer <http://www.freightman.com//Legal/QuoteDisclaimer> | All 
business is undertaken subject to our General Trading Conditions, a copy of 
which is available on request and on our website 
www.freightman.com<http://www.freightman.com/Legal/TradingTerms>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rboXgSmzH3cJ.
To post to this group, send email to django-users@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.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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