Navigate through FK field to related model

Fix regression introduced by 7d975637d5
when there is a misunderstanding while replacing deprecated rel.to
This commit is contained in:
Santiago L 2021-05-12 14:38:17 +02:00
parent aebbd424fc
commit 48ef1f21e3
10 changed files with 12 additions and 12 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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,))

View File

@ -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')

View File

@ -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):

View File

@ -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():

View File

@ -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')

View File

@ -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

View File

@ -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')

View File

@ -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)