On Wed, Dec 23, 2009 at 1:32 PM, Michael Manfre <[email protected]> wrote:
> With multiple database defined, what is the expected behavior for
> syncdb and the other db related commands?
The management commands all work the same way under multidb - they
only ever work on a single database at a time. If you don't specify a
database, the 'default' databse is used.
> The documentation shows that
> it is relatively easy to associate an admin form with a given
> database, but is there a way of associated a model or app to a given
> database?
Yes - ish. If you're working with your own application and models,
just define a custom manager for that model. The manager just needs to
override get_query_set() and applies a using() modifier:
class PersonManager(models.Manager):
def get_query_set(self):
return super(PersonManager, self).get_query_set().using('other')
class Person(models.Model):
objects = PersonManager()
name = models.CharField(max_length=50)
...
Unfortunately, this approach doesn't work for a model in a reusable
app - for example, you can't easily push contrib.auth.User to a
different database. However, you can just call
User.objects.using('other').... whenever you want to use the User
model.
I know this is less than ideal, but the goal for 1.2 was to complete
the plumbing and get the important porcelain in place (e.g., using()).
The goal for 1.3 is to identify the common end-user use cases for
multidb and make some easily exploitable hooks for end-users.
Yours,
Russ Magee %-)
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.