<commit_before>from django.db import models
from django.contrib.auth.models import User


class Question(models.Model):
    """Question Model
    - Every question has a CharField(text)
    - Every question has two ForeignKeys(asked_by, asked_to)
    - Every question has a DateTimeField(time)
    - Every question has a BooleanField(anonymous)
    """
    text = models.CharField(max_length=300, default=None)
    asked_to = models.ForeignKey(User, on_delete=models.CASCADE,
                                 related_name='asked_to_questions')
    asked_by = models.ForeignKey(User, default=None, null=True,
                                 related_name='asked_by_questions')
    time = models.DateTimeField(auto_now_add=True)
    anonymous = models.BooleanField(default=False)

    def __str__(self):
        return self.text[:40]

    def total_likes(self):
        """Returns the total likes count"""
        return self.likes.count()


class Answer(models.Model):
    """Answer Model
    - Every answer has a TextField(text)
    - Every answer has a DateTimeField(asked_at)
    - Every question has only one Answer"""
    text = models.TextField(default=None)
    question = models.OneToOneField(Question, on_delete=models.CASCADE)
    answered_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.text[:40]<commit_msg>Modify Question model so that a User cannot question himself<commit_after>from django.db import models
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User


class Question(models.Model):
    """Question Model
    - Every question has a CharField(text)
    - Every question has two ForeignKeys(asked_by, asked_to)
    - Every question has a DateTimeField(time)
    - Every question has a BooleanField(anonymous)
    """
    text = models.CharField(max_length=300, default=None)
    asked_to = models.ForeignKey(User, on_delete=models.CASCADE,
                                 related_name='asked_to_questions')
    asked_by = models.ForeignKey(User, default=None, null=True,
                                 related_name='asked_by_questions')
    time = models.DateTimeField(auto_now_add=True)
    anonymous = models.BooleanField(default=False)

    def __str__(self):
        return self.text[:40]

    def clean(self):
        if self.asked_by == self.asked_to:
            raise ValidationError(
                '%s cannot ask a question to himself' % self.asked_by.username
            )

    def save(self, *args, **kwargs):
        self.clean()
        return super(Question, self).save(*args, **kwargs)

    def total_likes(self):
        """Returns the total likes count"""
        return self.likes.count()


class Answer(models.Model):
    """Answer Model
    - Every answer has a TextField(text)
    - Every answer has a DateTimeField(asked_at)
    - Every question has only one Answer"""
    text = models.TextField(default=None)
    question = models.OneToOneField(Question, on_delete=models.CASCADE)
    answered_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.text[:40]
{'fraction_non_alphanumeric': 0.09632, 'fraction_numerical': 0.00448, 'mean_word_length': 3.054474708171206, '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': '1657822', 'n_tokens_mistral': 916, 'n_tokens_neox': 889, 'n_words': 224}