<commit_before>from django.db import models
from django.shortcuts import resolve_url as r
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify


import tagulous.models


class Idea(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=60)
    description = models.TextField()
    likes = models.ManyToManyField(User,
                                   blank=True,
                                   related_name='ideas_likes')
    slug = models.SlugField(max_length=60, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    tags = tagulous.models.TagField(
        blank=True,
        get_absolute_url=lambda tag: r(
            'core.views.by_tags', kwargs={'tags': tag.slug}
        ),
        max_count=5,
        force_lowercase=True,
    )

    def _get_unique_slug(self):
        slug = slugify(self.title)
        unique_slug = slug
        num = 1
        while Idea.objects.filter(slug=unique_slug).exists():
            unique_slug = f'{slug}-{num}'
            num += 1
        return unique_slug

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = self._get_unique_slug()
        super(Idea, self).save(*args, **kwargs)

    class Meta:
        ordering = ['-created_at']
        verbose_name = 'My Idea'
        verbose_name_plural = 'My Ideas'

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return r('idea_details', slug=self.slug)

    def get_api_like_url(self):
        return r('like_api', slug=self.slug)
<commit_msg>refactor models<commit_after>from django.db import models
from django.shortcuts import resolve_url as r
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify


import tagulous.models


class Idea(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=60)
    description = models.TextField()
    likes = models.ManyToManyField(User,
                                   blank=True,
                                   related_name='ideas_likes')
    slug = models.SlugField(max_length=60, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    tags = tagulous.models.TagField(
        blank=True,
        get_absolute_url=lambda tag: r(
            'core.views.by_tags', kwargs={'tags': tag.slug}
        ),
        max_count=5,
        force_lowercase=True,
    )

    class Meta:
        ordering = ['-created_at']
        verbose_name = 'My Idea'
        verbose_name_plural = 'My Ideas'

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = self._get_unique_slug()
        super(Idea, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return r('idea_details', slug=self.slug)

    def get_api_like_url(self):
        return r('like_api', slug=self.slug)

    def _get_unique_slug(self):
        slug = slugify(self.title)
        unique_slug = slug
        num = 1
        while Idea.objects.filter(slug=unique_slug).exists():
            unique_slug = f'{slug}-{num}'
            num += 1
        return unique_slug

{'fraction_non_alphanumeric': 0.10433190970103721, 'fraction_numerical': 0.004270896888346553, 'mean_word_length': 2.4014522821576763, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1840115', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1020, 'n_words': 203}