The router I was using was based on the router class in the Django multi-db
docs <https://docs.djangoproject.com/en/1.2/topics/db/multi-db/#an-example>,
so I assumed that the syntax would work.
They write:
class MyAppRouter(object):
"""A router to control all database operations on models in the myapp
application"""
def db_for_read(self, model, **hints):
"Point all operations on myapp models to 'other'"
if model._meta.app_label == 'myapp':
return 'other'
return None
But then the way they are invoking the method there is no instance of
MyAppRouter, so I worked around this with the following modification:
@staticmethod
def db_for_read(model, **hints):
Is there a reason the example looks like that, or is it Just Wrong?
On Tuesday, March 20, 2012 7:55:30 PM UTC-7, Chris Ghormley wrote:
>
> I'm having trouble with database routers in a Django 1.3.1 project.
> I'm by no means a Django or Python expert, but I've been using Django
> for a few years now. When I enable any kind of router in my project,
> it throws a TypeError like the following:
>
> "unbound method db_for_read() must be called with DBRouter instance as
> first argument (got ModelBase instance instead)"
>
> I've tried a few different examples based on the Django documentation,
> but it seems like I am missing something basic here.
>
> Does anybody have an idea what I've done wrong? Please let me know if
> you need more information.
>
> Here's some background:
>
> The new database is used by a new app with a model in the app's
> models.py. Using the shell I've proved that the database and model are
> OK.
>
> The routers.py is in the new app. The settings file imports the router
> class, and includes the following line:
>
> DATABASE_ROUTERS = [ DBRouter, ]
>
> Here's the basic layout:
> project
> settings.py
> app1 (uses database 1)
> models.py
> app2 (uses database 2)
> models.py
> routers.py
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/JT03_-ZLSIIJ.
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-users?hl=en.