django-orchestra/orchestra/contrib/webapps/fields.py
Santiago L 97f1c7ef2b Replace field.rel.to with field.remote_field.model
Field.rel and Field.remote_field.to are removed in Django 2.x
2021-04-22 14:44:47 +02:00

29 lines
975 B
Python

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 []
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
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 []
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)