Multiple database admin mixin
MultiDBModelAdmin
Admin to search/create/change objects from non-default database.
ModelAdmin attribute using
is for controlling which database
the QuerySet will be evaluated against if you are using more than
one database. The value is the alias of a database, as defined in DATABASES.
delete_model(self, request, obj)
Given a model instance delete it from the database.
Source code in pxd_admin_extensions/multidb.py
def delete_model(self, request, obj):
obj.delete(using=self.using)
save_model(self, request, obj, form, change)
Given a model instance save it to the database.
Source code in pxd_admin_extensions/multidb.py
def save_model(self, request, obj, form, change):
obj.save(using=self.using)
UsableAdminBaseMixin
Simpe mixin to apply default database key to the queryset resolver.
ModelAdmin attribute using
is for controlling which database
the QuerySet will be evaluated against if you are using more than
one database. The value is the alias of a database, as defined in DATABASES.
UsableForeignMixin
Mixin to add self using
kwarg usage to ModelAdmin for foreign fields.
using_kwarg_factory(func)
Simple method wrapper to get a default using parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable |
Wrapped method. |
required |
Source code in pxd_admin_extensions/multidb.py
def using_kwarg_factory(func):
"""Simple method wrapper to get a default using parameter.
Args:
func (Callable): Wrapped method.
"""
def method(self, *args, using=None, **kwargs):
return func(
self, *args, using=self.using if using is None else using, **kwargs
)
return wraps(func)(method)