<commit_before>from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.functional import cached_property

from .managers import ActivityItemManager


class Activity(models.Model):
    """
    Stores an action that occurred that is being tracked
    according to ACTIVITY_MONITOR settings.
    """
    actor = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name="subject",
    )
    timestamp = models.DateTimeField()

    verb = models.CharField(blank=True, null=True, max_length=255, editable=False)
    override_string = models.CharField(blank=True, null=True, max_length=255, editable=False)

    target = models.CharField(blank=True, null=True, max_length=255, editable=False)
    actor_name = models.CharField(blank=True, null=True, max_length=255, editable=False)

    content_object = GenericForeignKey()
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()

    objects = ActivityItemManager()

    class Meta:
        ordering = ['-timestamp']
        unique_together = [('content_type', 'object_id')]
        get_latest_by = 'timestamp'
        verbose_name_plural = 'actions'

    def __unicode__(self):
        return "{0}: {1}".format(self.content_type.model_class().__name__, self.content_object)

    def save(self, *args, **kwargs):
        """
        Store a string representation of content_object as target
        and actor name for fast retrieval and sorting.
        """
        if not self.target:
            self.target = str(self.content_object)
        if not self.actor_name:
            self.actor_name = str(self.actor)
        super(Activity, self).save()

    def get_absolute_url(self):
        """<commit_msg>Re-inserted on_delete<commit_after>from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.functional import cached_property

from .managers import ActivityItemManager


class Activity(models.Model):
    """
    Stores an action that occurred that is being tracked
    according to ACTIVITY_MONITOR settings.
    """
    actor = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name="subject",
        on_delete="CASCADE"
    )
    timestamp = models.DateTimeField()

    verb = models.CharField(blank=True, null=True, max_length=255, editable=False)
    override_string = models.CharField(blank=True, null=True, max_length=255, editable=False)

    target = models.CharField(blank=True, null=True, max_length=255, editable=False)
    actor_name = models.CharField(blank=True, null=True, max_length=255, editable=False)

    content_object = GenericForeignKey()
    content_type = models.ForeignKey(ContentType, on_delete="CASCADE")
    object_id = models.PositiveIntegerField()

    objects = ActivityItemManager()

    class Meta:
        ordering = ['-timestamp']
        unique_together = [('content_type', 'object_id')]
        get_latest_by = 'timestamp'
        verbose_name_plural = 'actions'

    def __unicode__(self):
        return "{0}: {1}".format(self.content_type.model_class().__name__, self.content_object)

    def save(self, *args, **kwargs):
        """
        Store a string representation of content_object as target
        and actor name for fast retrieval and sorting.
        """
        if not self.target:
            self.target = str(self.content_object)
        if not self.actor_name:
            self.actor_name = str(self.actor)
        super(Activity, self).save()

    def get_absolute_url(self):
        """
{'fraction_non_alphanumeric': 0.098117210289048, 'fraction_numerical': 0.007425086184036065, 'mean_word_length': 3.5065710872162486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7429660', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1052, 'n_words': 251}