From 48ef1f21e3b679de756aa5aa5e1d2e8619e0c3b5 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 12 May 2021 14:38:17 +0200 Subject: [PATCH] Navigate through FK field to related model Fix regression introduced by 7d975637d53d3711b5f8fbe49241d685c4bcf98d when there is a misunderstanding while replacing deprecated rel.to --- orchestra/contrib/accounts/actions.py | 2 +- orchestra/contrib/accounts/forms.py | 2 +- orchestra/contrib/bills/helpers.py | 2 +- orchestra/contrib/lists/serializers.py | 2 +- orchestra/contrib/mailboxes/models.py | 2 +- orchestra/contrib/orders/signals.py | 2 +- orchestra/contrib/saas/services/helpers.py | 4 ++-- orchestra/contrib/systemusers/models.py | 2 +- orchestra/contrib/websites/serializers.py | 4 ++-- orchestra/permissions/options.py | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/orchestra/contrib/accounts/actions.py b/orchestra/contrib/accounts/actions.py index da58022c..b4bcff22 100644 --- a/orchestra/contrib/accounts/actions.py +++ b/orchestra/contrib/accounts/actions.py @@ -175,7 +175,7 @@ def delete_related_services(modeladmin, request, queryset): for model, objs in collector.model_objs.items(): count = 0 # discount main systemuser - if model is modeladmin.model.main_systemuser.field.model: + if model is modeladmin.model.main_systemuser.field.related_model: count = len(objs) - 1 # Discount account elif model is not modeladmin.model and model in registered_services: diff --git a/orchestra/contrib/accounts/forms.py b/orchestra/contrib/accounts/forms.py index c3e308b1..a420c266 100644 --- a/orchestra/contrib/accounts/forms.py +++ b/orchestra/contrib/accounts/forms.py @@ -47,7 +47,7 @@ def create_account_creation_form(): # Previous validation error return errors = {} - systemuser_model = Account.main_systemuser.field.model + systemuser_model = Account.main_systemuser.field.related_model if systemuser_model.objects.filter(username=account.username).exists(): errors['username'] = _("A system user with this name already exists.") for model, key, related_kwargs, __ in create_related: diff --git a/orchestra/contrib/bills/helpers.py b/orchestra/contrib/bills/helpers.py index e5986b5c..23c72fcc 100644 --- a/orchestra/contrib/bills/helpers.py +++ b/orchestra/contrib/bills/helpers.py @@ -21,7 +21,7 @@ def validate_contact(request, bill, error=True): message = msg.format(relation=_("Related"), account=account, url=url) send(request, mark_safe(message)) valid = False - main = type(bill).account.field.model.objects.get_main() + main = type(bill).account.field.related_model.objects.get_main() if not hasattr(main, 'billcontact'): account = force_text(main) url = reverse('admin:accounts_account_change', args=(main.id,)) diff --git a/orchestra/contrib/lists/serializers.py b/orchestra/contrib/lists/serializers.py index c4a666fd..317e3e77 100644 --- a/orchestra/contrib/lists/serializers.py +++ b/orchestra/contrib/lists/serializers.py @@ -12,7 +12,7 @@ from .models import List class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class Meta: - model = List.address_domain.field.model + model = List.address_domain.field.related_model fields = ('url', 'id', 'name') diff --git a/orchestra/contrib/mailboxes/models.py b/orchestra/contrib/mailboxes/models.py index 8581d0ec..a38078ca 100644 --- a/orchestra/contrib/mailboxes/models.py +++ b/orchestra/contrib/mailboxes/models.py @@ -44,7 +44,7 @@ class Mailbox(models.Model): def active(self): try: return self.is_active and self.account.is_active - except type(self).account.field.model.DoesNotExist: + except type(self).account.field.related_model.DoesNotExist: return self.is_active def disable(self): diff --git a/orchestra/contrib/orders/signals.py b/orchestra/contrib/orders/signals.py index c1b541e8..1778a3da 100644 --- a/orchestra/contrib/orders/signals.py +++ b/orchestra/contrib/orders/signals.py @@ -15,7 +15,7 @@ def cancel_orders(sender, **kwargs): if sender._meta.app_label not in settings.ORDERS_EXCLUDED_APPS: instance = kwargs['instance'] # Account delete will delete all related orders, no need to maintain order consistency - if isinstance(instance, Order.account.field.model): + if isinstance(instance, Order.account.field.related_model): return if type(instance) in services: for order in Order.objects.by_object(instance).active(): diff --git a/orchestra/contrib/saas/services/helpers.py b/orchestra/contrib/saas/services/helpers.py index 7418bc9d..a08855fe 100644 --- a/orchestra/contrib/saas/services/helpers.py +++ b/orchestra/contrib/saas/services/helpers.py @@ -42,7 +42,7 @@ def clean_custom_url(saas): ) except Website.DoesNotExist: # get or create domain - Domain = Website.domains.field.model + Domain = Website.domains.field.related_model try: domain = Domain.objects.get(name=url.netloc) except Domain.DoesNotExist: @@ -110,7 +110,7 @@ def create_or_update_directive(saas): account=account, ) except Website.DoesNotExist: - Domain = Website.domains.field.model + Domain = Website.domains.field.related_model domain = Domain.objects.get(name=url.netloc) # Create new website for custom_url tgt_server = Server.objects.get(name='web.pangea.lan') diff --git a/orchestra/contrib/systemusers/models.py b/orchestra/contrib/systemusers/models.py index 92576646..b270bcad 100644 --- a/orchestra/contrib/systemusers/models.py +++ b/orchestra/contrib/systemusers/models.py @@ -61,7 +61,7 @@ class SystemUser(models.Model): def active(self): try: return self.is_active and self.account.is_active - except type(self).account.field.model.DoesNotExist: + except type(self).account.field.related_model.DoesNotExist: return self.is_active @cached_property diff --git a/orchestra/contrib/websites/serializers.py b/orchestra/contrib/websites/serializers.py index f38203a3..49eb2b6f 100644 --- a/orchestra/contrib/websites/serializers.py +++ b/orchestra/contrib/websites/serializers.py @@ -13,13 +13,13 @@ from .validators import validate_domain_protocol class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class Meta: - model = Website.domains.field.model + model = Website.domains.field.related_model fields = ('url', 'id', 'name') class RelatedWebAppSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class Meta: - model = Content.webapp.field.model + model = Content.webapp.field.related_model fields = ('url', 'id', 'name', 'type') diff --git a/orchestra/permissions/options.py b/orchestra/permissions/options.py index b37d2363..7e48196a 100644 --- a/orchestra/permissions/options.py +++ b/orchestra/permissions/options.py @@ -90,7 +90,7 @@ class RelatedPermission(Permission): if obj is None: parent = cls for relation in relations: - parent = getattr(parent, relation).field.model + parent = getattr(parent, relation).field.related_model else: parent = functools.reduce(getattr, relations, obj)