Replace field.rel.to with field.remote_field.model

Field.rel and Field.remote_field.to are removed in Django 2.x
This commit is contained in:
Santiago L 2021-04-22 14:44:47 +02:00
parent b6cf0c34f5
commit 97f1c7ef2b
9 changed files with 32 additions and 35 deletions

View File

@ -27,7 +27,7 @@ def create_local_address(sender, *args, **kwargs):
mbox = kwargs['instance'] mbox = kwargs['instance']
local_domain = settings.MAILBOXES_LOCAL_DOMAIN local_domain = settings.MAILBOXES_LOCAL_DOMAIN
if not mbox.pk and local_domain: if not mbox.pk and local_domain:
Domain = Address._meta.get_field('domain').rel.to Domain = Address._meta.get_field('domain').remote_field.model
try: try:
domain = Domain.objects.get(name=local_domain) domain = Domain.objects.get(name=local_domain)
except Domain.DoesNotExist: except Domain.DoesNotExist:

View File

@ -16,7 +16,7 @@ def get_related_object(origin, max_depth=2):
if hasattr(field, 'ct_field'): if hasattr(field, 'ct_field'):
yield getattr(node, field.name) yield getattr(node, field.name)
for field in node._meta.fields: for field in node._meta.fields:
if field.rel: if field.remote_field:
try: try:
yield getattr(node, field.name) yield getattr(node, field.name)
except ObjectDoesNotExist: except ObjectDoesNotExist:

View File

@ -98,7 +98,7 @@ class ResourceAdmin(ExtendedModelAdmin):
""" filter service content_types """ """ filter service content_types """
if db_field.name == 'content_type': if db_field.name == 'content_type':
models = [ model._meta.model_name for model in services.get() ] models = [ model._meta.model_name for model in services.get() ]
kwargs['queryset'] = db_field.rel.to.objects.filter(model__in=models) kwargs['queryset'] = db_field.remote_field.model.objects.filter(model__in=models)
return super(ResourceAdmin, self).formfield_for_dbfield(db_field, **kwargs) return super(ResourceAdmin, self).formfield_for_dbfield(db_field, **kwargs)

View File

@ -342,7 +342,7 @@ def create_resource_relation():
pass pass
else: else:
related._meta.private_fields = [ related._meta.private_fields = [
field for field in related._meta.private_fields if field.rel.to != ResourceData field for field in related._meta.private_fields if field.remote_field.model != ResourceData
] ]
for ct, resources in Resource.objects.group_by('content_type').items(): for ct, resources in Resource.objects.group_by('content_type').items():

View File

@ -11,5 +11,4 @@ class VirtualDatabaseRelation(GenericRelation):
pks.append(obj.database_id) pks.append(obj.database_id)
if not pks: if not pks:
return [] return []
# TODO renamed to self.remote_field in django 1.8 return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
return self.rel.to._base_manager.db_manager(using).filter(pk__in=pks)

View File

@ -168,7 +168,7 @@ class DBSoftwareService(SoftwareService):
@cached @cached
def get_account(self): def get_account(self):
account_model = self.instance._meta.get_field('account') account_model = self.instance._meta.get_field('account')
return account_model.rel.to.objects.get_main() return account_model.remote_field.model.objects.get_main()
def validate(self): def validate(self):
super(DBSoftwareService, self).validate() super(DBSoftwareService, self).validate()

View File

@ -59,7 +59,7 @@ class ServiceAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
""" Improve performance of account field and filter by account """ """ Improve performance of account field and filter by account """
if db_field.name == 'content_type': if db_field.name == 'content_type':
models = [model._meta.model_name for model in services.get()] models = [model._meta.model_name for model in services.get()]
queryset = db_field.rel.to.objects queryset = db_field.remote_field.model.objects
kwargs['queryset'] = queryset.filter(model__in=models) kwargs['queryset'] = queryset.filter(model__in=models)
if db_field.name in ['match', 'metric', 'order_description']: if db_field.name in ['match', 'metric', 'order_description']:
kwargs['widget'] = forms.TextInput(attrs={'size':'160'}) kwargs['widget'] = forms.TextInput(attrs={'size':'160'})

View File

@ -12,8 +12,7 @@ class VirtualDatabaseRelation(GenericRelation):
pks.append(db_id) pks.append(db_id)
if not pks: if not pks:
return [] return []
# TODO renamed to self.remote_field in django 1.8 return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
return self.rel.to._base_manager.db_manager(using).filter(pk__in=pks)
class VirtualDatabaseUserRelation(GenericRelation): class VirtualDatabaseUserRelation(GenericRelation):
@ -26,5 +25,4 @@ class VirtualDatabaseUserRelation(GenericRelation):
pks.append(db_id) pks.append(db_id)
if not pks: if not pks:
return [] return []
# TODO renamed to self.remote_field in django 1.8 return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
return self.rel.to._base_manager.db_manager(using).filter(pk__in=pks)

View File

@ -50,9 +50,9 @@ def get_model_field_path(origin, target):
if node == target: if node == target:
return path return path
for field in node._meta.fields: for field in node._meta.fields:
if field.rel: if field.remote_field:
new_model = list(model) new_model = list(model)
new_model.append(field.rel.to) new_model.append(field.remote_field.model)
new_path = list(path) new_path = list(path)
new_path.append(field.name) new_path.append(field.name)
queue.append((new_model, new_path)) queue.append((new_model, new_path))