Re: Multiple DB in django 1.2

2010-02-25 Thread Russell Keith-Magee
On Fri, Feb 26, 2010 at 2:08 AM, Roach, Marshall (MROACH)
 wrote:
> Hi, I was at pycon last week and heard about the db routers in django 1.2
> and I have the alpha version of django running for a project I’m running and
> trying to figure out how to do the following.
>
> I have 2 databases on different machines and if its one of the models I want
> the database to write everything to both machines.

Writing a single object to two different databases wasn't one of the
design goals of multi-db. I can't think of an easy way to do this with
a router.

The easiest way I can think of would be to overwrite the save() method
on a model to do something like the following:

class MyModel(models.Model):
def save(self, *args, **kwargs):
super(MyModel, self).save(*args, **dict(kwargs, using='database1'))
return super(MyModel, self).save(*args, **dict(kwargs,
using='database2'))

That is, intercept the save to force a model save to do 2 saves, one
on each database you want to target.

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.



Multiple DB in django 1.2

2010-02-25 Thread Roach, Marshall (MROACH)
Hi, I was at pycon last week and heard about the db routers in django 1.2
and I have the alpha version of django running for a project I¹m running and
trying to figure out how to do the following.

I have 2 databases on different machines and if its one of the models I want
the database to write everything to both machines.

I¹m running postgresql and having issues trying to get my router right and
didn¹t know if anyone else has done this before.

Thanks,

Marshall 

-- 

Marshall Roach
mro...@arinc.com


-
This e-mail (including any attachments) is intended only for the use of the
individual or entity named above and may contain privileged, proprietary, or
confidential information.  The information may also contain technical data
subject to export control laws.
-

Please consider the environment before printing this email.

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