<commit_before>from django.db import models
from grandchallenge.core.models import UUIDModel
from grandchallenge.cases.models import Image


class Archive(UUIDModel):
    """
    Model for archive. Contains a collection of images
    """

    name = models.CharField(max_length=255, default="Unnamed Archive")

    images = models.ManyToManyField(Image)

    def __str__(self):
        return "<{} {}>".format(self.__class__.__name__, self.name)
<commit_msg>Cascade delete all related models when deleting an archive<commit_after>from django.db import models
from grandchallenge.core.models import UUIDModel
from grandchallenge.cases.models import Image
from grandchallenge.patients.models import Patient


class Archive(UUIDModel):
    """
    Model for archive. Contains a collection of images
    """

    name = models.CharField(max_length=255, default="Unnamed Archive")

    images = models.ManyToManyField(Image)

    def __str__(self):
        return f"<{self.__class__.__name__} {self.name}>"

    def delete(self, *args, **kwargs):
        # Remove all related patients and other models via cascading
        Patient.objects.filter(study__image__archive__id=self.id).delete()
        super().delete(*args, **kwargs)

{'fraction_non_alphanumeric': 0.100326264274062, 'fraction_numerical': 0.004893964110929853, 'mean_word_length': 4.15546218487395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2632512', 'n_tokens_mistral': 363, 'n_tokens_neox': 332, 'n_words': 94}