diff --git a/scipost_django/scipost/models.py b/scipost_django/scipost/models.py index 89ee085ac2788ef352152b404f401284b33bfb7c..c8d0af2c42506051849f5b8c255ad93388bfa136 100644 --- a/scipost_django/scipost/models.py +++ b/scipost_django/scipost/models.py @@ -6,6 +6,7 @@ import datetime import hashlib import random import string +from typing import TYPE_CHECKING from django.urls import reverse from django.conf import settings @@ -39,6 +40,9 @@ from conflicts.models import ConflictOfInterest today = timezone.now().date() +if TYPE_CHECKING: + from django.contrib.auth.models import User + def get_sentinel_user(): """Temporary fix to be able to delete Contributor instances. @@ -84,7 +88,7 @@ class Contributor(models.Model): profile = models.OneToOneField( "profiles.Profile", on_delete=models.SET_NULL, null=True, blank=True ) - user = models.OneToOneField( + user = models.OneToOneField["User"]( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, unique=True ) invitation_key = models.CharField(max_length=40, blank=True) diff --git a/scipost_django/submissions/models/report.py b/scipost_django/submissions/models/report.py index c2965329186409f5eca0c078bc2d3d978bba9d92..a4441c1e84027e06d0a3b2083217af225e894cd7 100644 --- a/scipost_django/submissions/models/report.py +++ b/scipost_django/submissions/models/report.py @@ -3,6 +3,7 @@ __license__ = "AGPL v3" import subprocess +from typing import TYPE_CHECKING from django.contrib.contenttypes.fields import GenericRelation from django.db import models from django.db.models.signals import post_save @@ -34,6 +35,10 @@ from ..constants import ( ) from ..managers import ReportQuerySet +if TYPE_CHECKING: + from scipost.models import Contributor + from submissions.models import Submission + class Report(SubmissionRelatedObjectMixin, models.Model): """Report on a Submission, written by a Contributor.""" @@ -44,7 +49,7 @@ class Report(SubmissionRelatedObjectMixin, models.Model): report_type = models.CharField( max_length=32, choices=REPORT_TYPES, default=REPORT_NORMAL ) - submission = models.ForeignKey( + submission = models.ForeignKey["Submission"]( "submissions.Submission", related_name="reports", on_delete=models.CASCADE ) report_nr = models.PositiveSmallIntegerField( @@ -53,7 +58,7 @@ class Report(SubmissionRelatedObjectMixin, models.Model): "refeering to the Report nr. of " "the Submission", ) - vetted_by = models.ForeignKey( + vetted_by = models.ForeignKey["Contributor"]( "scipost.Contributor", related_name="report_vetted_by", blank=True, @@ -66,7 +71,7 @@ class Report(SubmissionRelatedObjectMixin, models.Model): # `flagged' if author of report has been flagged by submission authors (surname check only) flagged = models.BooleanField(default=False) - author = models.ForeignKey( + author = models.ForeignKey["Contributor"]( "scipost.Contributor", on_delete=models.CASCADE, related_name="reports" ) qualification = models.PositiveSmallIntegerField(