old_contents: from django.db import models
  from django.core.validators import RegexValidator
  from jsonfield import JSONField
  
  
  class Metric(models.Model):
      # automatically set data
      date_created = models.DateTimeField(auto_now_add=True)
      creator_path = models.CharField(max_length=1024, validators=[
          RegexValidator("^(/[^/]*)+/?$")])
  
      # metadata stored for humans
      title = models.CharField(max_length=100, unique=True)
      description = models.TextField(default="", blank=True)
      keywords = models.CharField(default="", blank=True, max_length=400,
                                  validators=[RegexValidator(
                                      "^([_\-a-zA-Z0-9]+ ?($|,))+")])
  
      indicator_id = models.IntegerField()
      formula = models.TextField()
      variables = JSONField()
  
new_contents: from jsonfield import JSONField
  
  from django.db import models
  from django.core.validators import RegexValidator
  from django.db.models.signals import post_delete
  
  from apps.datasetmanager.models import Dataset
  
  
  class Metric(models.Model):
      # automatically set data
      date_created = models.DateTimeField(auto_now_add=True)
      creator_path = models.CharField(max_length=1024, validators=[
          RegexValidator("^(/[^/]*)+/?$")])
  
      # metadata stored for humans
      title = models.CharField(max_length=100, unique=True)
      description = models.TextField(default="", blank=True)
      keywords = models.CharField(default="", blank=True, max_length=400,
                                  validators=[RegexValidator(
                                      "^([_\-a-zA-Z0-9]+ ?($|,))+")])
  
      indicator_id = models.IntegerField()
      formula = models.TextField()
      variables = JSONField()
  
      def __str__(self):
          return self.title
  
  
  def clean_datasets(sender, instance, **kwargs):
      id = instance.id
      datasets = Dataset.objects.filter(metric_id=id)
      for dataset in datasets:
          dataset.metric_id = None
          dataset.description = ''
          dataset.save()
  
  post_delete.connect(clean_datasets, sender=Metric)
  
subject: add post_delete signal to metric