views:

98

answers:

1

I'm trying to get a queryset to issue its query over a different DB connection, using a different cursor class. Does anyone know if that's possible and if so how it might be done? In psuedo-code:

  # setup a new db connection:
  db = db_connect(cursorclass=AlternateCursor)

  # setup a generic queryset
  qset = blah.objects.all()

  # tell qset to use the new connection:
  qset.use_db(db)

  # and then apply some filters
  qset = qset.filter(...)

  # and execute the query:
  for object in qset:
     ...

Thanks!

+1  A: 

This is possible from Django 1.0 on - the trick is to use a custom manager for your model and replace the manager's connection object. See the code at Eric Florenzano's post at http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/

Simeon
Thanks, this is very helpful!
samtregar