Hi guys,
Could you please advise in the following:
registry is the project, BGP is the app, default is the sqlite db, registry is
a postgres db
the admin.py looks like this:
class MultiDBModelAdmin(admin.ModelAdmin):
# A handy constant for the name of the alternate database.
using = "registry"
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)
class BGPcommunitiesAdmin(MultiDBModelAdmin):
list_display = ("comm_name", "comm_value", "used_as", "label",
"modified_on")
search_fields = ("comm_name", "comm_value", "label")
list_filter = ("used_as", "modified_on")
admin.site.register(BGPcommunities, BGPcommunitiesAdmin)
registryadmin = admin.AdminSite("registryadmin")
registryadmin.register(BGPcommunities, BGPcommunitiesAdmin)
and the urls.py looks like this:
from BGP.admin import registryadmin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^registryadmin/', registryadmin.urls),]
The issue is that I cannot save any record in the database (the table is
not found).
This can be fixed by tweaking
/usr/lib/python2.7/site-packages/django/db/models/query.py:
def exists(self):
other_db = 'registry'
if self._result_cache is None:
try:
return self.query.has_results(using=self.db)
except:
return self.query.has_results(using=other_db)
return bool(self._result_cache)
The original version was:
def exists(self):
if self._result_cache is None:
return self.query.has_results(using=self.db)
return bool(self._result_cache)
Could you please advise who to solve this the proper way ? It seems that
the connection tot he databases is not using the registry database, but the
default one.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/750705f7-2e04-4ca8-9747-7552f2475c4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.