from hvad.contrib.restframework import TranslatableModelSerializer
from rest_framework import serializers
from rest_framework.reverse import reverse

from .models import Category, TargetGroup, TargetAge, Event
from pagoeta.apps.core.functions import get_absolute_uri
from pagoeta.apps.places.serializers import PlaceListSerializer


class TypeField(serializers.RelatedField):
    def to_representation(self, value):
        return {
            'code': value.code,
            'name': value.name
        }


class EventSerializer(TranslatableModelSerializer):
    category = TypeField(read_only=True)
    target_group = TypeField(read_only=True)
    targetGroup = target_group
    target_age = TypeField(read_only=True)
    targetAge = target_age
    place = PlaceListSerializer(read_only=True)
    # camelCase some field names
    startAt = serializers.DateTimeField(source='start_at', read_only=True)
    endAt = serializers.DateTimeField(source='end_at', read_only=True)
    isFeatured = serializers.BooleanField(source='is_featured', read_only=True)
    isVisible = serializers.BooleanField(source='is_visible', read_only=True)
    href = serializers.SerializerMethodField()

    class Meta(object):
        model = Event
        exclude = ('start_at', 'end_at', 'is_featured', 'is_visible', 'language_code')

    def get_href(self, obj):
        return get_absolute_uri(reverse('v1:event-detail', [obj.id]))

from hvad.contrib.restframework import TranslatableModelSerializer
from rest_framework import serializers
from rest_framework.reverse import reverse

from .models import Category, TargetGroup, TargetAge, Event
from pagoeta.apps.core.functions import get_absolute_uri
from pagoeta.apps.places.serializers import PlaceListSerializer


class TypeField(serializers.RelatedField):
    def to_representation(self, value):
        return {
            'code': value.code,
            'name': value.name
        }


class EventSerializer(TranslatableModelSerializer):
    category = TypeField(read_only=True)
    place = PlaceListSerializer(read_only=True)
    # camelCase some field names
    targetGroup = TypeField(source='target_group', read_only=True)
    targetAge = TypeField(source='target_age', read_only=True)
    startAt = serializers.DateTimeField(source='start_at', read_only=True)
    endAt = serializers.DateTimeField(source='end_at', read_only=True)
    isFeatured = serializers.BooleanField(source='is_featured', read_only=True)
    isVisible = serializers.BooleanField(source='is_visible', read_only=True)
    href = serializers.SerializerMethodField()

    class Meta(object):
        model = Event
        exclude = ('target_group', 'target_age', 'start_at', 'end_at', 'is_featured', 'is_visible', 'language_code')

    def get_href(self, obj):
        return get_absolute_uri(reverse('v1:event-detail', [obj.id]))

Change camelCasing strategy for `target_age` and `target_group`
Change camelCasing strategy for `target_age` and `target_group`

  from hvad.contrib.restframework import TranslatableModelSerializer
  from rest_framework import serializers
  from rest_framework.reverse import reverse
  
  from .models import Category, TargetGroup, TargetAge, Event
  from pagoeta.apps.core.functions import get_absolute_uri
  from pagoeta.apps.places.serializers import PlaceListSerializer
  
  
  class TypeField(serializers.RelatedField):
      def to_representation(self, value):
          return {
              'code': value.code,
              'name': value.name
          }
  
  
  class EventSerializer(TranslatableModelSerializer):
      category = TypeField(read_only=True)
-     target_group = TypeField(read_only=True)
-     targetGroup = target_group
-     target_age = TypeField(read_only=True)
-     targetAge = target_age
      place = PlaceListSerializer(read_only=True)
      # camelCase some field names
+     targetGroup = TypeField(source='target_group', read_only=True)
+     targetAge = TypeField(source='target_age', read_only=True)
      startAt = serializers.DateTimeField(source='start_at', read_only=True)
      endAt = serializers.DateTimeField(source='end_at', read_only=True)
      isFeatured = serializers.BooleanField(source='is_featured', read_only=True)
      isVisible = serializers.BooleanField(source='is_visible', read_only=True)
      href = serializers.SerializerMethodField()
  
      class Meta(object):
          model = Event
-         exclude = ('start_at', 'end_at', 'is_featured', 'is_visible', 'language_code')
+         exclude = ('target_group', 'target_age', 'start_at', 'end_at', 'is_featured', 'is_visible', 'language_code')
  
      def get_href(self, obj):
          return get_absolute_uri(reverse('v1:event-detail', [obj.id]))
  
Change camelCasing strategy for `target_age` and `target_group`
## Code Before:
from hvad.contrib.restframework import TranslatableModelSerializer
from rest_framework import serializers
from rest_framework.reverse import reverse

from .models import Category, TargetGroup, TargetAge, Event
from pagoeta.apps.core.functions import get_absolute_uri
from pagoeta.apps.places.serializers import PlaceListSerializer


class TypeField(serializers.RelatedField):
    def to_representation(self, value):
        return {
            'code': value.code,
            'name': value.name
        }


class EventSerializer(TranslatableModelSerializer):
    category = TypeField(read_only=True)
    target_group = TypeField(read_only=True)
    targetGroup = target_group
    target_age = TypeField(read_only=True)
    targetAge = target_age
    place = PlaceListSerializer(read_only=True)
    # camelCase some field names
    startAt = serializers.DateTimeField(source='start_at', read_only=True)
    endAt = serializers.DateTimeField(source='end_at', read_only=True)
    isFeatured = serializers.BooleanField(source='is_featured', read_only=True)
    isVisible = serializers.BooleanField(source='is_visible', read_only=True)
    href = serializers.SerializerMethodField()

    class Meta(object):
        model = Event
        exclude = ('start_at', 'end_at', 'is_featured', 'is_visible', 'language_code')

    def get_href(self, obj):
        return get_absolute_uri(reverse('v1:event-detail', [obj.id]))

## Instruction:
Change camelCasing strategy for `target_age` and `target_group`
## Code After:
from hvad.contrib.restframework import TranslatableModelSerializer
from rest_framework import serializers
from rest_framework.reverse import reverse

from .models import Category, TargetGroup, TargetAge, Event
from pagoeta.apps.core.functions import get_absolute_uri
from pagoeta.apps.places.serializers import PlaceListSerializer


class TypeField(serializers.RelatedField):
    def to_representation(self, value):
        return {
            'code': value.code,
            'name': value.name
        }


class EventSerializer(TranslatableModelSerializer):
    category = TypeField(read_only=True)
    place = PlaceListSerializer(read_only=True)
    # camelCase some field names
    targetGroup = TypeField(source='target_group', read_only=True)
    targetAge = TypeField(source='target_age', read_only=True)
    startAt = serializers.DateTimeField(source='start_at', read_only=True)
    endAt = serializers.DateTimeField(source='end_at', read_only=True)
    isFeatured = serializers.BooleanField(source='is_featured', read_only=True)
    isVisible = serializers.BooleanField(source='is_visible', read_only=True)
    href = serializers.SerializerMethodField()

    class Meta(object):
        model = Event
        exclude = ('target_group', 'target_age', 'start_at', 'end_at', 'is_featured', 'is_visible', 'language_code')

    def get_href(self, obj):
        return get_absolute_uri(reverse('v1:event-detail', [obj.id]))
