# Path: shared_schema_tenants_custom_data/serializers.py
# class TenantSpecificModelSerializer(serializers.ModelSerializer):
# 
#     serializer_tenant_specific_field_mapping = {
#         'integer': serializers.IntegerField,
#         'char': serializers.CharField,
#         'text': serializers.CharField,
#         'float': serializers.FloatField,
#         'datetime': serializers.DateTimeField,
#         'date': serializers.DateField,
#     }
# 
#     data_type_fields = {
#         'integer': models.IntegerField(),
#         'char': models.CharField(max_length=255),
#         'text': models.TextField(),
#         'float': models.FloatField(),
#         'datetime': models.DateTimeField(),
#         'date': models.DateField(),
#     }
# 
#     def __init__(self, *args, **kwargs):
#         ModelClass = self.Meta.model
# 
#         self.tenant_specific_fields_definitions = TenantSpecificFieldDefinition.objects.filter(
#             table_content_type=ContentType.objects.get_for_model(ModelClass))
# 
#         self.tenant_specific_fields_names = list(
#             self.tenant_specific_fields_definitions.values_list('name', flat=True))
# 
#         for definition in self.tenant_specific_fields_definitions:
#             if not hasattr(self, definition.name):
#                 field_kwargs = {}
#                 if definition.is_required:
#                     field_kwargs.update({
#                         'required': True,
#                         'allow_null': True
#                     })
#                 if definition.default_value is not None:
#                     field_kwargs.update({'default': definition.default_value})
# 
#                 setattr(self, definition.name,
#                         self.serializer_tenant_specific_field_mapping[definition.data_type](**field_kwargs))
# 
#         super(TenantSpecificModelSerializer, self).__init__(*args, **kwargs)
# 
#     def get_field_names(self, declared_fields, info):
#         fields = super(TenantSpecificModelSerializer, self).get_field_names(declared_fields, info)
#         return fields + self.tenant_specific_fields_names
# 
#     def to_internal_value(self, data):
#         ret = OrderedDict()
#         errors = OrderedDict()
# 
#         for field in self.tenant_specific_fields_definitions:
#             validators = []
#             for validator_instance in field.validators.all():
#                 validator_function = import_from_string(validator_instance.module_path)
#                 validators.append(validator_function)
# 
#             validate_method = compose_list(validators)
# 
#             primitive_value = self.fields.get(field.name).get_value(data)
#             try:
#                 validated_value = self.fields.get(field.name).run_validation(primitive_value)
#                 if validate_method is not None:
#                     validated_value = validate_method(validated_value)
#             except serializers.ValidationError as exc:
#                 errors[field.name] = exc.detail
#             except DjangoValidationError as exc:
#                 errors[field.name] = get_error_detail(exc)
#             except SkipField:
#                 pass
#             else:
#                 set_value(ret, self.fields.get(field.name).source_attrs, validated_value)
# 
#         if errors:
#             raise serializers.ValidationError(errors)
# 
#         data.update(dict(ret))
# 
#         ret = super(TenantSpecificModelSerializer, self).to_internal_value(data)
# 
#         return ret
# 
#     def build_field(self, field_name, info, model_class, nested_depth):
#         tenat_specific_fields_names = list(
#             self.tenant_specific_fields_definitions.values_list('name', flat=True))
#         if field_name in tenat_specific_fields_names:
#             definition = self.tenant_specific_fields_definitions.get(name=field_name)
#             return self.build_standard_field(field_name, self.data_type_fields[definition.data_type])
# 
#         return super(TenantSpecificModelSerializer, self).build_field(
#             field_name, info, model_class, nested_depth)
# 
#     def create(self, validated_data):
#         ModelClass = self.Meta.model
#         instance = ModelClass.objects.create(**validated_data)
#         return ModelClass.objects.get(pk=instance.pk)
# 
#     def update(self, instance, validated_data):
#         ModelClass = self.Meta.model
#         instance = super(TenantSpecificModelSerializer, self).update(instance, validated_data)
#         return ModelClass.objects.get(pk=instance.pk)
# 
# Path: exampleproject/lectures/models.py
# class Lecture(TenantSpecificFieldsModelMixin):
#     subject = models.CharField(max_length=100)
#     description = models.TextField()
#     speaker = models.ForeignKey(settings.AUTH_USER_MODEL)
# 
#     def __str__(self):
#         return '%s - %s' % (self.subject, self.speaker)


from rest_framework import serializers
from shared_schema_tenants_custom_data.serializers import TenantSpecificModelSerializer
from .models import Lecture



class LectureSerializer(TenantSpecificModelSerializer):
    speaker_name = serializers.SerializerMethodField()

    class Meta:
        model = Lecture
        fields = ['id', 'subject', 'speaker', 'speaker_name', 'description']


# Path: shared_schema_tenants_custom_data/serializers.py
# class TenantSpecificModelSerializer(serializers.ModelSerializer):
# 
#     serializer_tenant_specific_field_mapping = {
#         'integer': serializers.IntegerField,
#         'char': serializers.CharField,
#         'text': serializers.CharField,
#         'float': serializers.FloatField,
#         'datetime': serializers.DateTimeField,
#         'date': serializers.DateField,
#     }
# 
#     data_type_fields = {
#         'integer': models.IntegerField(),
#         'char': models.CharField(max_length=255),
#         'text': models.TextField(),
#         'float': models.FloatField(),
#         'datetime': models.DateTimeField(),
#         'date': models.DateField(),
#     }
# 
#     def __init__(self, *args, **kwargs):
#         ModelClass = self.Meta.model
# 
#         self.tenant_specific_fields_definitions = TenantSpecificFieldDefinition.objects.filter(
#             table_content_type=ContentType.objects.get_for_model(ModelClass))
# 
#         self.tenant_specific_fields_names = list(
#             self.tenant_specific_fields_definitions.values_list('name', flat=True))
# 
#         for definition in self.tenant_specific_fields_definitions:
#             if not hasattr(self, definition.name):
#                 field_kwargs = {}
#                 if definition.is_required:
#                     field_kwargs.update({
#                         'required': True,
#                         'allow_null': True
#                     })
#                 if definition.default_value is not None:
#                     field_kwargs.update({'default': definition.default_value})
# 
#                 setattr(self, definition.name,
#                         self.serializer_tenant_specific_field_mapping[definition.data_type](**field_kwargs))
# 
#         super(TenantSpecificModelSerializer, self).__init__(*args, **kwargs)
# 
#     def get_field_names(self, declared_fields, info):
#         fields = super(TenantSpecificModelSerializer, self).get_field_names(declared_fields, info)
#         return fields + self.tenant_specific_fields_names
# 
#     def to_internal_value(self, data):
#         ret = OrderedDict()
#         errors = OrderedDict()
# 
#         for field in self.tenant_specific_fields_definitions:
#             validators = []
#             for validator_instance in field.validators.all():
#                 validator_function = import_from_string(validator_instance.module_path)
#                 validators.append(validator_function)
# 
#             validate_method = compose_list(validators)
# 
#             primitive_value = self.fields.get(field.name).get_value(data)
#             try:
#                 validated_value = self.fields.get(field.name).run_validation(primitive_value)
#                 if validate_method is not None:
#                     validated_value = validate_method(validated_value)
#             except serializers.ValidationError as exc:
#                 errors[field.name] = exc.detail
#             except DjangoValidationError as exc:
#                 errors[field.name] = get_error_detail(exc)
#             except SkipField:
#                 pass
#             else:
#                 set_value(ret, self.fields.get(field.name).source_attrs, validated_value)
# 
#         if errors:
#             raise serializers.ValidationError(errors)
# 
#         data.update(dict(ret))
# 
#         ret = super(TenantSpecificModelSerializer, self).to_internal_value(data)
# 
#         return ret
# 
#     def build_field(self, field_name, info, model_class, nested_depth):
#         tenat_specific_fields_names = list(
#             self.tenant_specific_fields_definitions.values_list('name', flat=True))
#         if field_name in tenat_specific_fields_names:
#             definition = self.tenant_specific_fields_definitions.get(name=field_name)
#             return self.build_standard_field(field_name, self.data_type_fields[definition.data_type])
# 
#         return super(TenantSpecificModelSerializer, self).build_field(
#             field_name, info, model_class, nested_depth)
# 
#     def create(self, validated_data):
#         ModelClass = self.Meta.model
#         instance = ModelClass.objects.create(**validated_data)
#         return ModelClass.objects.get(pk=instance.pk)
# 
#     def update(self, instance, validated_data):
#         ModelClass = self.Meta.model
#         instance = super(TenantSpecificModelSerializer, self).update(instance, validated_data)
#         return ModelClass.objects.get(pk=instance.pk)
# 
# Path: exampleproject/lectures/models.py
# class Lecture(TenantSpecificFieldsModelMixin):
#     subject = models.CharField(max_length=100)
#     description = models.TextField()
#     speaker = models.ForeignKey(settings.AUTH_USER_MODEL)
# 
#     def __str__(self):
#         return '%s - %s' % (self.subject, self.speaker)


# Path: exampleproject/lectures/serializers.py
from rest_framework import serializers
from shared_schema_tenants_custom_data.serializers import TenantSpecificModelSerializer
from .models import Lecture




class LectureSerializer(TenantSpecificModelSerializer):
    speaker_name = serializers.SerializerMethodField()

    class Meta:
        model = Lecture
        fields = ['id', 'subject', 'speaker', 'speaker_name', 'description']


    def get_speaker_name(self, obj):