<commit_before>from django.contrib.contenttypes.models import ContentType

from .models import Follow


class UserFollowMixin(object):

    def follow(self, item):
        item_type = ContentType.objects.get_for_model(item)
        Follow.objects.create(
            user=self,
            target_content_type=item_type,
            target_object_id=item.pk
        )

    def unfollow(self, item):
        item_type = ContentType.objects.get_for_model(item)
        Follow.objects.filter(
            user=self,
            target_content_type=item_type,
            target_object_id=item.pk
        ).delete()

    def is_following(self, item):
        item_type = ContentType.objects.get_for_model(item)
        return Follow.objects.filter(
            user=self,
            target_content_type=item_type,
            target_object_id=item.pk
        ).exists()<commit_msg>use get_or_create to stop multiple follow objects being created<commit_after>from django.contrib.contenttypes.models import ContentType

from .models import Follow


class UserFollowMixin(object):

    def follow(self, item):
        item_type = ContentType.objects.get_for_model(item)
        Follow.objects.get_or_create(
            user=self,
            target_content_type=item_type,
            target_object_id=item.pk
        )

    def unfollow(self, item):
        item_type = ContentType.objects.get_for_model(item)
        Follow.objects.filter(
            user=self,
            target_content_type=item_type,
            target_object_id=item.pk
        ).delete()

    def is_following(self, item):
        item_type = ContentType.objects.get_for_model(item)
        return Follow.objects.filter(
            user=self,
            target_content_type=item_type,
            target_object_id=item.pk
        ).exists()
{'fraction_non_alphanumeric': 0.08052950910093767, 'fraction_numerical': 0.0, 'mean_word_length': 2.403377110694184, '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': '6790316', 'n_tokens_mistral': 525, 'n_tokens_neox': 514, 'n_words': 87}