#30760: Django admin "view on site" button doesn't respect database routers
-----------------------------------------+-------------------------------
Reporter: zooqooo | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.2
Severity: Normal | Keywords: Admin, Router
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-------------------------------
I'm using the default admin view 'django.contrib.admin'.
Here is an excerpt from my app_1.models.py
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class SomeModel(models.Model):
name = models.CharField(max_length=50)
slug_name = models.SlugField(max_length=75, unique=True)
#Some more fields
def get_absolute_url(self):
return reverse("siteSomeModel", kwargs={"slug": self.slug_name})
}}}
}}}
Here is an excerpt from my site.routers.py
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class App_1_DataBaseRouter():
label = "app_1"
db = "app_1_db"
def db_for_read(self, model, **hints):
if model._meta.app_label == self.label:
return self.db
return None
def db_for_write(self, model, **hints):
if model._meta.app_label == self.label:
return self.db
return None
def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label == self.label and obj2._meta.app_label ==
self.label:
return True
if self.label not in [obj1._meta.app_label, obj2._meta.app_label]:
return None
return False
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == self.label:
return db == self.db
if db == self.db:
return False
return None
}}}
}}}
when I run in the shell it works
{{{
>>>python manage.py shell
>>>from app_1.models import SomeModel
>>>ob=SomeModel.objects.get(name='Some Name')
>>>ob.get_absolute_url()
app1/SomeModel/some-name
}}}
But when I click on view on site in the admin view I get
{{{
OperationalError at /admin/r/18/1/
no such table: app_1_SomeModel
}}}
And I can see with Django-debug-toolbar that this is because it is
connected to the default database instead of app_1_db. I have no other
issues with routing in the admin app or elsewhere
--
Ticket URL: <https://code.djangoproject.com/ticket/30760>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.2543746d7ab0936945039242f9c38231%40djangoproject.com.