This is my whole module. I can’t figure out what could cause this problem, but I will try to set up a test module with not that much content and check if that will link the right detail view.
class Institution(models.Model):
class QualityLevelCoordinatesChoices(models.TextChoices):
NO_ENTRY = "no_entry", _("no entry")
UNCHECKED = "unchecked", _("unchecked")
PRELIMINARILY_CHECKED = "preliminarily_checked", _("preliminarily checked")
CHECKED = "checked", _("checked")
class TypeChoices(models.TextChoices):
# TODO explanations missing
HES = "HES", _("secondary and higher education establishment")
OTH = "OTH", _("other entity")
PRC = "PRC", _("private for profit company")
PUB = "PUB", _("public body, excluding research and education")
REC = "REC", _("research organisation, excluding education")
UNKNOWN = "unk", _("unknown")
class SubtypeChoices(models.TextChoices):
SME = "SME", _("micro, small and medium-sized enterprise")
LRE = "LRE", _("large enterprise")
UNKNOWN = "unk", _("unknown size")
name = models.CharField(
verbose_name=_("Name of the institution"),
max_length=200,
)
abbreviation = models.CharField( # null=False, but "" allowed. Is Django convention
verbose_name=_("Acronym"),
max_length=25,
blank=True,
help_text=_("if applicable"),
)
parent_institution = models.ForeignKey(
"self",
verbose_name=_("Parent institution"),
on_delete=models.SET_NULL,
blank=True,
null=True,
help_text=_("if applicable"),
)
street = models.CharField(
verbose_name=_("Street of head office"),
max_length=150,
blank=True,
)
add_to_address = models.CharField(
verbose_name=_("Extra address information"),
max_length=150,
blank=True,
)
house_number = models.CharField(
verbose_name=_("House number"),
max_length=12,
blank=True,
)
postal_code = models.CharField(
verbose_name=_("Postal code"),
max_length=12,
blank=True,
)
city = models.CharField(
verbose_name=_("City"),
max_length=100,
blank=True,
)
country = models.CharField(
verbose_name=_("Country"),
max_length=150,
blank=True,
)
geo_latitude = models.DecimalField(
max_digits=11, decimal_places=6, blank=True, null=True
)
geo_longitude = models.DecimalField(
max_digits=11, decimal_places=6, blank=True, null=True
)
quality_level_coordinates = models.CharField(
max_length=30,
verbose_name="Quality of the coordinates",
choices=QualityLevelCoordinatesChoices.choices,
default=QualityLevelCoordinatesChoices.NO_ENTRY,
)
website = models.URLField(
verbose_name=_("Main website"),
max_length=200,
blank=True,
)
legal_form = models.CharField(
verbose_name=_("Legal form"),
max_length=100,
blank=True,
)
type_of_organization = models.CharField(
max_length=3,
choices=TypeChoices.choices,
default=TypeChoices.UNKNOWN,
)
subtype_of_organization = models.CharField(
max_length=3, choices=SubtypeChoices.choices, blank=True
)
contact_notes = models.TextField(
verbose_name=_("Notes about contacting this institution"),
blank=True,
max_length=1000,
)
internal_contact_at_dbfz = models.CharField(
verbose_name=_("Internal contact"),
max_length=500,
blank=True,
help_text=_("Ask this employee at DBFZ how to contact this institution."),
)
nuts_level_3 = models.ForeignKey(
NutsLevel3,
on_delete=models.PROTECT,
blank=True,
null=True,
)
# Django makes ManyToMany relationships unique by default (that means DBFZ can't be in 'A' two times)
nace_sections = models.ManyToManyField(NaceSection, related_name="nace_sections")
nace_divisions = models.ManyToManyField(NaceDivision, blank=True)
nace_groups = models.ManyToManyField(NaceGroup, blank=True)
nace_classes = models.ManyToManyField(NaceClass, blank=True)
keywords = models.ManyToManyField(Keyword, blank=True)
data_used_in_dbfz_projects = (
models.ManyToManyField( # stakeholders_institution_data_used_in_dbfz_projects
DbfzProject,
related_name="used_data_of_institutions",
blank=True, # DBFZProject.used_data_of_institutions
)
)
partner_in_dbfz_projects = models.ManyToManyField(
DbfzProject,
related_name="partner_institutions",
blank=True, # DBFZProject.partner_institutions
)
class Meta:
verbose_name = _("Institution")
verbose_name_plural = _("Institutions")
def __str__(self):
if self.abbreviation:
return f"{self.name} ({self.abbreviation})"
else:
return f"{self.name}"
# TODO translate validation error
def clean(self):
if self.subtype_of_organization:
if self.type_of_organization != self.TypeChoices.PRC:
raise ValidationError(
f'Subtype of organization may only be set if type of organization is "{self.TypeChoices.PRC.label}"'
)
if (
self.type_of_organization == self.TypeChoices.PRC
and not self.subtype_of_organization
):
raise ValidationError(
f'If type of organization is "{self.TypeChoices.PRC.label}" please also set subtype of organization'
)