suggestion on querying external database

143 views
Skip to first unread message

tekion

unread,
May 10, 2009, 9:01:04 AM5/10/09
to Django users
Hi,
I have an application which update MySQL database. It has
aproximately 5 million rows. I am new to django, I am thinking of
using django to generate report using the database as the data source.
From what I have seen of the tutorial, you create a model. The
database model, would create some sort of schema on the database of
your setting (depending on what option you have set up on your
setting.py file). Update,ADD, MOD,Query would go against this
schema. What I am not sure is, what if you don't want to
UPDATE,ADD,MOD, just select from the (external) database because
another application is responsible for the data in the database? Does
any one have ideas on how to best handle this?

From what I have seen with Django, I would have to write my own code
snippet to handle the query for the report in conjunction with Django
template system.

Dougal Matthews

unread,
May 10, 2009, 9:13:11 AM5/10/09
to django...@googlegroups.com
This might be useful; http://docs.djangoproject.com/en/dev/howto/legacy-databases/

It describes how to create models for your existing databases. However, it wont stop you being able to make writes with the django ORM.

Dougal


---
Dougal Matthews - @d0ugal
http://www.dougalmatthews.com/



2009/5/10 tekion <tek...@gmail.com>

tekion

unread,
May 10, 2009, 8:45:35 PM5/10/09
to Django users
Yes. I saw this link. My impression on first read is that it imports
the database into Django's database. I am not looking for this. I am
looking to just be able to read in the data from the external database
and leave the maintenance of the database to the external
application. Has anyone done gone done this path with Django. If
not, then I am thinking of writing my own code to generate the report
and just use Django for displaying the data. Thoughts?

On May 10, 9:13 am, Dougal Matthews <douga...@gmail.com> wrote:
> This might be useful;http://docs.djangoproject.com/en/dev/howto/legacy-databases/
> It describes how to create models for your existing databases. However, it
> wont stop you being able to make writes with the django ORM.
>
> Dougal
>
> ---
> Dougal Matthews - @d0ugalhttp://www.dougalmatthews.com/

Karen Tracey

unread,
May 10, 2009, 9:41:05 PM5/10/09
to django...@googlegroups.com
On Sun, May 10, 2009 at 8:45 PM, tekion <tek...@gmail.com> wrote:

Yes. I saw this link. My impression on first read is that it imports
the database into Django's database. I am not looking for this. I am
looking to just be able to read in the data from the external database
and leave the maintenance of the database to the external
application.   Has anyone done gone done this path with Django.  If
not, then I am thinking of writing my own code to generate the report
and just use Django for displaying the data.  Thoughts?


I think you may be misunderstanding that page.  inspectdb looks at your existing database tables and generates Django models that you can use to access those tables.  If you only want to query those tables, then you can do that.  You can still use whatever other methods you have in place to update the existing tables, and your Django code that uses the generated models will see the updates.  That is, inspectdb does not do any sort of 'import' from one DB to another, it simply provides a start at the Python code you need to access your existing tables from a Django application.

Now, if you are going to be using Django-included apps like authentication, admin, and session support, those apps require their own tables and (at least until multi-DB support is added) those tables will need to be added to your existing database.  You cannot currently easily segregate tables for one app into one DB and tables for another app into another DB.

When I started with Django I was looking to add a web front-end to my existing database.  I already had other tools to update the DB and was not interested at that point in doing any updates from Django, I just wanted a web front-end to see the data in ways I could not using my other tools.  I was also pretty paranoid about letting this new untrusted tool change any of my existing data, so I set up the database user I specified in settings.py to not have any privileges that would let Django code make any changes to my existing tables.  So you can use Django for read-only access to existing tables....I did it for quite a while, until I decided to migrate my update tools to a Django/web interface as well.

Karen

tekion

unread,
May 11, 2009, 11:17:01 AM5/11/09
to Django users
Thanks for the update. This is very useful information.
Reply all
Reply to author
Forward
0 new messages