<commit_before>import uuid

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _


class MessageQuerySet(models.query.QuerySet):
    """Personalized queryset created to improve model usability"""

    def get_conversation(self, sender, recipient):
        """Returns all the messages sent between two users."""
        qs_one = self.filter(sender=sender, recipient=recipient)
        qs_two = self.filter(sender=recipient, recipient=sender)
        return qs_one.union(qs_two).order_by('-timestamp')


class Message(models.Model):
    """A private message sent between users.
    """
    uuid_id = models.UUIDField(
        primary_key=True, default=uuid.uuid4, editable=False)
    sender = models.ForeignKey(
        settings.AUTH_USER_MODEL, related_name='sent_messages',
        verbose_name=_("Sender"), null=True, on_delete=models.SET_NULL)
    recipient = models.ForeignKey(
        settings.AUTH_USER_MODEL, related_name='received_messages', null=True,
        blank=True, verbose_name=_("Recipient"), on_delete=models.SET_NULL)
    timestamp = models.DateTimeField(auto_now_add=True)
    message = models.TextField(max_length=1000, blank=True)
    is_read = models.BooleanField(default=False)
    objects = MessageQuerySet.as_manager()

    class Meta:
        verbose_name = _("Message")
        verbose_name_plural = _("Messages")

    def __str__(self):
        return self.message<commit_msg>Adding new methods.<commit_after>import uuid

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _


class MessageQuerySet(models.query.QuerySet):
    """Personalized queryset created to improve model usability"""

    def get_conversation(self, sender, recipient):
        """Returns all the messages sent between two users."""
        qs_one = self.filter(sender=sender, recipient=recipient)
        qs_two = self.filter(sender=recipient, recipient=sender)
        return qs_one.union(qs_two).order_by('-timestamp')

    def mark_conversation_as_read(self, sender, recipient):
        """Mark as read any unread elements in the current conversation.
        """
        qs = self.filter(sender=sender, recipient=recipient)
        return qs.update(unread=False)


class Message(models.Model):
    """A private message sent between users.
    """
    uuid_id = models.UUIDField(
        primary_key=True, default=uuid.uuid4, editable=False)
    sender = models.ForeignKey(
        settings.AUTH_USER_MODEL, related_name='sent_messages',
        verbose_name=_("Sender"), null=True, on_delete=models.SET_NULL)
    recipient = models.ForeignKey(
        settings.AUTH_USER_MODEL, related_name='received_messages', null=True,
        blank=True, verbose_name=_("Recipient"), on_delete=models.SET_NULL)
    timestamp = models.DateTimeField(auto_now_add=True)
    message = models.TextField(max_length=1000, blank=True)
    unread = models.BooleanField(default=True, db_index=True)
    objects = MessageQuerySet.as_manager()

    class Meta:
        verbose_name = _("Message")
        verbose_name_plural = _("Messages")

    def __str__(self):
        return self.message

    def mark_as_read(self):
        """Method to mark a message as read"""
        if self.unread:
            self.unread = False
            self.save()

    def send_new_message(self, sender, recipient, message):
        """Method to create a new message in a conversation.
        :requires:

        :param sender: User instance of the user sending the message.
        :param recipient: User instance of the user to recieve the message.
        :param message: Text piece shorter than 1000 characters containing the
                        actual message.
        """
        new_message = Message.object.create(
            sender=sender,
            recipient=recipient
            message=message
        )
{'fraction_non_alphanumeric': 0.09668367346938775, 'fraction_numerical': 0.0035714285714285713, 'mean_word_length': 3.390817469204927, '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': '1046598', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1083, 'n_words': 270}