exposing multiple databases in django admin
<p>My use case requires me to expose multiple databases in the admin site of my django project. Did that following this link: <a href="https://docs.djangoproject.com/en/dev/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface</a></p>

<p>Here's the code used:</p>

<pre><code>class MultiDBModelAdmin(admin.ModelAdmin):
# A handy constant for the name of the alternate database.
using = 'other'

def save_model(self, request, obj, form, change):
    # Tell Django to save objects to the 'other' database.
    obj.save(using=self.using)

def delete_model(self, request, obj):
    # Tell Django to delete objects from the 'other' database
    obj.delete(using=self.using)

def get_queryset(self, request):
    # Tell Django to look for objects on the 'other' database.
    return super(MultiDBModelAdmin, self).get_queryset(request).using(self.using)

def formfield_for_foreignkey(self, db_field, request, **kwargs):
    # Tell Django to populate ForeignKey widgets using a query
    # on the 'other' database.
    return super(MultiDBModelAdmin, self).formfield_for_foreignkey(db_field, request, using=self.using, **kwargs)

def formfield_for_manytomany(self, db_field, request, **kwargs):
    # Tell Django to populate ManyToMany widgets using a query
    # on the 'other' database.
    return super(MultiDBModelAdmin, self).formfield_for_manytomany(db_field, request, using=self.using, **kwargs)
</code></pre>

<p>And then:</p>

<pre><code>admin.site.register(Author, MultiDBModelAdmin)
admin.site.register(Publisher, PublisherAdmin)

othersite = admin.AdminSite('othersite')
othersite.register(Publisher, MultiDBModelAdmin)
</code></pre>

<p>The example's documentation states: This example sets up two admin sites. On the first site, the Author and Publisher objects are exposed; Publisher objects have an tabular inline showing books published by that publisher. The second site exposes just publishers, without the inlines.</p>

<p>What I don't seem to find out anywhere is: how do I access the other 'site'? What URL has to be used to view the tables exposed in the other 'site'? Should be something straightforward, but I cannot seem to find it anywhere.</p>

<p>You need to add a url pattern for your admin site, similar to how you enable the regular site:</p>

<pre><code># urls.py
from django.conf.urls import url
from django.contrib import admin
from myapp.admin import othersite

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^otheradmin/', othersite.urls),
]
</code></pre>

<p>You then access the other admin at whatever url you used. In this case, <code>/otheradmin/</code>.</p>

<p>This syntax is for Django 1.10+. On earlier versions of Django, you use <code>include(othersite.urls)</code> instead of <code>othersite.urls</code>.</p>

python django django-admin