MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / Metadata

Class Metadata

api/metadata/models.py:117–140  ·  view source on GitHub ↗

This model represents the actual metadata attached to a specific instance of a model e.g: Environment.objects.get(id=1).metadata

Source from the content-addressed store, hash-verified

115
116
117class Metadata(AbstractBaseExportableModel):
118 """This model represents the actual metadata attached to a specific instance of a model
119 e.g: Environment.objects.get(id=1).metadata
120
121 """
122
123 content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
124 object_id = GenericObjectID()
125 content_object = GenericForeignKey("content_type", "object_id")
126 model_field = models.ForeignKey(MetadataModelField, on_delete=models.CASCADE)
127 field_value = models.TextField(max_length=FIELD_VALUE_MAX_LENGTH)
128
129 class Meta:
130 unique_together = ("model_field", "content_type", "object_id")
131
132 def deep_clone_for_new_entity(self, cloned_entity: models.Model) -> "Metadata":
133 content_type = ContentType.objects.get_for_model(cloned_entity)
134 metadata: Metadata = Metadata.objects.create(
135 model_field=self.model_field,
136 content_type=content_type,
137 object_id=cloned_entity.pk,
138 field_value=self.field_value,
139 )
140 return metadata

Calls 1

GenericObjectIDClass · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…