<commit_before>from django.core.exceptions import ValidationError
from django.db.models import ManyToManyField
from django.db.models.loading import get_model
from ..serializers.field_deserializers import get_deserializer
from .base_serializer import BaseSerializer
from .object_map import get_object_map


class DjangoModelSerializer(BaseSerializer):
    model = None
    include_related = []
    instance = None

    def __init__(self, instance=None, context=None, **kwargs):
        super(DjangoModelSerializer, self).__init__(context, **kwargs)
        self.base_channel = '{}'.format(self._model().__name__)
        if instance:
            self.instance = instance

    @classmethod
    def _model(cls):
        if isinstance(cls.model, str):
            cls.model = get_model(*cls.model.split('.', 1))
        return cls.model

    @classmethod
    def get_base_channel(cls):
        if cls.base_channel:
            return '{}|'.format(cls.base_channel)
        return '{}|'.format(cls._get_type_name())

    @classmethod
    def _get_type_name(cls):
        return cls._model()._meta.model_name

    @classmethod
    def get_related_fields(cls):
        pub_fields = cls.get_publish_fields()
        return [f for f in pub_fields if hasattr(cls._model(), f)]

    @classmethod
    def _get_publish_m2m_fields(cls):
        related_fields = cls.get_related_fields()
        m2m_fields = []
        for f in related_fields:
            field = getattr(cls._model(), f)
            if hasattr(field, 'field'):
                field = field.field
            elif hasattr(field, 'related'):
                field = field.related.field
            if isinstance(field, ManyToManyField):<commit_msg>Exclude properties from the related fields<commit_after>from django.core.exceptions import ValidationError
from django.db.models import ManyToManyField
from django.db.models.loading import get_model
from ..serializers.field_deserializers import get_deserializer
from .base_serializer import BaseSerializer
from .object_map import get_object_map


class DjangoModelSerializer(BaseSerializer):
    model = None
    include_related = []
    instance = None

    def __init__(self, instance=None, context=None, **kwargs):
        super(DjangoModelSerializer, self).__init__(context, **kwargs)
        self.base_channel = '{}'.format(self._model().__name__)
        if instance:
            self.instance = instance

    @classmethod
    def _model(cls):
        if isinstance(cls.model, str):
            cls.model = get_model(*cls.model.split('.', 1))
        return cls.model

    @classmethod
    def get_base_channel(cls):
        if cls.base_channel:
            return '{}|'.format(cls.base_channel)
        return '{}|'.format(cls._get_type_name())

    @classmethod
    def _get_type_name(cls):
        return cls._model()._meta.model_name

    @classmethod
    def get_related_fields(cls):
        pub_fields = cls.get_publish_fields()
        m = cls._model()
        return [f for f in pub_fields if hasattr(m, f) and not isinstance(getattr(m, f), property)]

    @classmethod
    def _get_publish_m2m_fields(cls):
        related_fields = cls.get_related_fields()
        m2m_fields = []
        for f in related_fields:
            field = getattr(cls._model(), f)
            if hasattr(field, 'field'):
                field = field.field
            elif hasattr(field, 'related'):
                field = field.related.field
            if isinstance(field, ManyToManyField):
{'fraction_non_alphanumeric': 0.10060189165950129, 'fraction_numerical': 0.0017196904557179708, 'mean_word_length': 2.8183807439824946, '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': '6981217', 'n_tokens_mistral': 1014, 'n_tokens_neox': 996, 'n_words': 231}