|
1 |
| -from urllib.parse import urlparse |
2 | 1 | from typing import cast
|
| 2 | +from urllib.parse import urlparse |
| 3 | + |
3 | 4 | from django.contrib.contenttypes.fields import GenericForeignKey
|
4 | 5 | from django.contrib.contenttypes.models import ContentType
|
5 | 6 | from django.db import models
|
@@ -29,13 +30,18 @@ class FieldType(models.TextChoices):
|
29 | 30 |
|
30 | 31 | class MetadataField(AbstractBaseExportableModel):
|
31 | 32 | """This model represents a metadata field(specific to an organisation) that can be attached to any model"""
|
| 33 | + |
32 | 34 | id: models.AutoField[int, int]
|
33 | 35 | name: models.CharField[str, str] = models.CharField(max_length=255)
|
34 | 36 | type: models.CharField[str, str] = models.CharField(
|
35 | 37 | max_length=255, choices=FieldType.choices, default=FieldType.STRING
|
36 | 38 | )
|
37 |
| - description: models.TextField[str | None, str | None] = models.TextField(blank=True, null=True) |
38 |
| - organisation: models.ForeignKey[Organisation, Organisation] = models.ForeignKey(Organisation, on_delete=models.CASCADE) |
| 39 | + description: models.TextField[str | None, str | None] = models.TextField( |
| 40 | + blank=True, null=True |
| 41 | + ) |
| 42 | + organisation: models.ForeignKey[Organisation, Organisation] = models.ForeignKey( |
| 43 | + Organisation, on_delete=models.CASCADE |
| 44 | + ) |
39 | 45 |
|
40 | 46 | def is_field_value_valid(self, field_value: str) -> bool:
|
41 | 47 | if len(field_value) > FIELD_VALUE_MAX_LENGTH:
|
@@ -64,7 +70,7 @@ def validate_url(self, field_value: str) -> bool:
|
64 | 70 | def validate_str(self, field_value: str) -> bool:
|
65 | 71 | return True
|
66 | 72 |
|
67 |
| - def validate_multiline_str(self, field_value: str) -> bool: |
| 73 | + def validate_multiline_str(self, field_value: str) -> bool: |
68 | 74 | return True
|
69 | 75 |
|
70 | 76 | class Meta:
|
@@ -115,10 +121,15 @@ class Metadata(AbstractBaseExportableModel):
|
115 | 121 | class Meta:
|
116 | 122 | unique_together = ("model_field", "content_type", "object_id")
|
117 | 123 |
|
118 |
| - def deep_clone_for_new_entity(self, cloned_entity: models.Model, content_type: ContentType) -> "Metadata": |
119 |
| - return cast(Metadata, Metadata.objects.create( |
120 |
| - model_field=self.model_field, |
121 |
| - content_type=content_type, |
122 |
| - object_id=cloned_entity.pk, |
123 |
| - field_value=self.field_value, |
124 |
| - )) |
| 124 | + def deep_clone_for_new_entity( |
| 125 | + self, cloned_entity: models.Model, content_type: ContentType |
| 126 | + ) -> "Metadata": |
| 127 | + return cast( |
| 128 | + Metadata, |
| 129 | + Metadata.objects.create( |
| 130 | + model_field=self.model_field, |
| 131 | + content_type=content_type, |
| 132 | + object_id=cloned_entity.pk, |
| 133 | + field_value=self.field_value, |
| 134 | + ), |
| 135 | + ) |
0 commit comments