Replace ForeignKey.field.rel.to --> field.model

rel.to dropped on Django 2.0
This commit is contained in:
Santiago L 2021-04-22 10:44:09 +02:00
parent d863598d81
commit 7d975637d5
11 changed files with 52 additions and 52 deletions

View File

@ -175,7 +175,7 @@ def delete_related_services(modeladmin, request, queryset):
for model, objs in collector.model_objs.items(): for model, objs in collector.model_objs.items():
count = 0 count = 0
# discount main systemuser # discount main systemuser
if model is modeladmin.model.main_systemuser.field.rel.to: if model is modeladmin.model.main_systemuser.field.model:
count = len(objs) - 1 count = len(objs) - 1
# Discount account # Discount account
elif model is not modeladmin.model and model in registered_services: 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 # Previous validation error
return return
errors = {} errors = {}
systemuser_model = Account.main_systemuser.field.rel.to systemuser_model = Account.main_systemuser.field.model
if systemuser_model.objects.filter(username=account.username).exists(): if systemuser_model.objects.filter(username=account.username).exists():
errors['username'] = _("A system user with this name already exists.") errors['username'] = _("A system user with this name already exists.")
for model, key, related_kwargs, __ in create_related: 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) message = msg.format(relation=_("Related"), account=account, url=url)
send(request, mark_safe(message)) send(request, mark_safe(message))
valid = False valid = False
main = type(bill).account.field.rel.to.objects.get_main() main = type(bill).account.field.model.objects.get_main()
if not hasattr(main, 'billcontact'): if not hasattr(main, 'billcontact'):
account = force_text(main) account = force_text(main)
url = reverse('admin:accounts_account_change', args=(main.id,)) url = reverse('admin:accounts_account_change', args=(main.id,))

View File

@ -12,7 +12,7 @@ from .models import List
class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer):
class Meta: class Meta:
model = List.address_domain.field.rel.to model = List.address_domain.field.model
fields = ('url', 'id', 'name') fields = ('url', 'id', 'name')

View File

@ -44,7 +44,7 @@ class Mailbox(models.Model):
def active(self): def active(self):
try: try:
return self.is_active and self.account.is_active return self.is_active and self.account.is_active
except type(self).account.field.rel.to.DoesNotExist: except type(self).account.field.model.DoesNotExist:
return self.is_active return self.is_active
def disable(self): def disable(self):

View File

@ -8,7 +8,7 @@ from .models import Mailbox, Address
class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer):
class Meta: class Meta:
model = Address.domain.field.rel.to model = Address.domain.field.model
fields = ('url', 'id', 'name') fields = ('url', 'id', 'name')

View File

@ -15,7 +15,7 @@ def cancel_orders(sender, **kwargs):
if sender._meta.app_label not in settings.ORDERS_EXCLUDED_APPS: if sender._meta.app_label not in settings.ORDERS_EXCLUDED_APPS:
instance = kwargs['instance'] instance = kwargs['instance']
# Account delete will delete all related orders, no need to maintain order consistency # Account delete will delete all related orders, no need to maintain order consistency
if isinstance(instance, Order.account.field.rel.to): if isinstance(instance, Order.account.field.model):
return return
if type(instance) in services: if type(instance) in services:
for order in Order.objects.by_object(instance).active(): for order in Order.objects.by_object(instance).active():

View File

@ -42,7 +42,7 @@ def clean_custom_url(saas):
) )
except Website.DoesNotExist: except Website.DoesNotExist:
# get or create domain # get or create domain
Domain = Website.domains.field.rel.to Domain = Website.domains.field.model
try: try:
domain = Domain.objects.get(name=url.netloc) domain = Domain.objects.get(name=url.netloc)
except Domain.DoesNotExist: except Domain.DoesNotExist:
@ -110,7 +110,7 @@ def create_or_update_directive(saas):
account=account, account=account,
) )
except Website.DoesNotExist: except Website.DoesNotExist:
Domain = Website.domains.field.rel.to Domain = Website.domains.field.model
domain = Domain.objects.get(name=url.netloc) domain = Domain.objects.get(name=url.netloc)
# Create new website for custom_url # Create new website for custom_url
tgt_server = Server.objects.get(name='web.pangea.lan') tgt_server = Server.objects.get(name='web.pangea.lan')

View File

@ -61,7 +61,7 @@ class SystemUser(models.Model):
def active(self): def active(self):
try: try:
return self.is_active and self.account.is_active return self.is_active and self.account.is_active
except type(self).account.field.rel.to.DoesNotExist: except type(self).account.field.model.DoesNotExist:
return self.is_active return self.is_active
@cached_property @cached_property

View File

@ -13,13 +13,13 @@ from .validators import validate_domain_protocol
class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class RelatedDomainSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer):
class Meta: class Meta:
model = Website.domains.field.rel.to model = Website.domains.field.model
fields = ('url', 'id', 'name') fields = ('url', 'id', 'name')
class RelatedWebAppSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer): class RelatedWebAppSerializer(AccountSerializerMixin, RelatedHyperlinkedModelSerializer):
class Meta: class Meta:
model = Content.webapp.field.rel.to model = Content.webapp.field.model
fields = ('url', 'id', 'name', 'type') fields = ('url', 'id', 'name', 'type')

View File

@ -90,7 +90,7 @@ class RelatedPermission(Permission):
if obj is None: if obj is None:
parent = cls parent = cls
for relation in relations: for relation in relations:
parent = getattr(parent, relation).field.rel.to parent = getattr(parent, relation).field.model
else: else:
parent = functools.reduce(getattr, relations, obj) parent = functools.reduce(getattr, relations, obj)