2015-03-27 19:50:54 +00:00
|
|
|
from django.contrib.contenttypes.fields import GenericRelation
|
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
|
|
|
|
|
|
|
|
|
|
|
class VirtualDatabaseRelation(GenericRelation):
|
|
|
|
""" Delete related databases if any """
|
|
|
|
def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
|
|
|
|
pks = []
|
|
|
|
for obj in objs:
|
|
|
|
db_id = obj.data.get('db_id')
|
|
|
|
if db_id:
|
|
|
|
pks.append(db_id)
|
|
|
|
if not pks:
|
|
|
|
return []
|
2021-04-22 12:44:47 +00:00
|
|
|
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
|
2015-03-27 19:50:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VirtualDatabaseUserRelation(GenericRelation):
|
|
|
|
""" Delete related databases if any """
|
|
|
|
def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
|
|
|
|
pks = []
|
|
|
|
for obj in objs:
|
|
|
|
db_id = obj.data.get('db_user_id')
|
|
|
|
if db_id:
|
|
|
|
pks.append(db_id)
|
|
|
|
if not pks:
|
|
|
|
return []
|
2021-04-22 12:44:47 +00:00
|
|
|
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
|