RE: Alternative to the .using() method

2011-10-12 Thread Sells, Fred
Thanks, is exactly what I need.

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jacob Kaplan-Moss
Sent: Tuesday, October 11, 2011 5:36 PM
To: django-users@googlegroups.com
Subject: Re: Alternative to the .using() method

On Tue, Oct 11, 2011 at 3:47 PM, Sells, Fred
 wrote:
> I'm using a MySQL database and one table resides in a separate database
> than all the others.  It's a generic logging table.
>
> I understand the use of the .using() method, but I wonder if there is a
> way to specify the alternative model in the model definition so I don't
> have to depend on remembering to add the .using() method in any usage.
>
> I could create a view in mysql and make the model "unmanaged" but was
> wondering if there is a more pythonic way?

Indeed there is: what you're looking for is called a "database
router", and you can find documentation here:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#automatic-database-routing

In your particular case, you'll implement something very similar to
the first example presented there: if the app is your logging app, use
the logging connection; otherwise, use the default connection.

Jacob

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


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



Re: Alternative to the .using() method

2011-10-11 Thread Jacob Kaplan-Moss
On Tue, Oct 11, 2011 at 3:47 PM, Sells, Fred
 wrote:
> I'm using a MySQL database and one table resides in a separate database
> than all the others.  It's a generic logging table.
>
> I understand the use of the .using() method, but I wonder if there is a
> way to specify the alternative model in the model definition so I don't
> have to depend on remembering to add the .using() method in any usage.
>
> I could create a view in mysql and make the model "unmanaged" but was
> wondering if there is a more pythonic way?

Indeed there is: what you're looking for is called a "database
router", and you can find documentation here:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#automatic-database-routing

In your particular case, you'll implement something very similar to
the first example presented there: if the app is your logging app, use
the logging connection; otherwise, use the default connection.

Jacob

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



Alternative to the .using() method

2011-10-11 Thread Sells, Fred
I'm using a MySQL database and one table resides in a separate database
than all the others.  It's a generic logging table.

I understand the use of the .using() method, but I wonder if there is a
way to specify the alternative model in the model definition so I don't
have to depend on remembering to add the .using() method in any usage.

I could create a view in mysql and make the model "unmanaged" but was
wondering if there is a more pythonic way?


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