from core.models import ApplicationVersion as ImageVersion
from rest_framework import serializers
from api.v2.serializers.summaries import LicenseSerializer
from api.v2.serializers.summaries import ImageVersionSummarySerializer
from api.v2.serializers.fields import ProviderMachineRelatedField


class ImageVersionSerializer(serializers.HyperlinkedModelSerializer):

    """
    Serializer for ApplicationVersion (aka 'image_version')
    """
    # NOTE: Implicitly included via 'fields'
    # id, application
    parent = ImageVersionSummarySerializer()
    #name, change_log, allow_imaging
    licenses = LicenseSerializer(many=True, read_only=True)  # NEW
    membership = serializers.SlugRelatedField(
        slug_field='name',
        read_only=True,
        many=True)  # NEW
    machines = ProviderMachineRelatedField(many=True)
    start_date = serializers.DateTimeField()
    end_date = serializers.DateTimeField()

    class Meta:
        model = ImageVersion
        view_name = 'api:v2:providermachine-detail'
        fields = ('id', 'parent', 'name', 'change_log',
                  'machines', 'allow_imaging',
                  'licenses', 'membership',
                  'start_date', 'end_date')

from core.models import ApplicationVersion as ImageVersion
from rest_framework import serializers
from api.v2.serializers.summaries import (
        LicenseSerializer,
        UserSummarySerializer,
        IdentitySummarySerializer,
        ImageVersionSummarySerializer)
from api.v2.serializers.fields import ProviderMachineRelatedField


class ImageVersionSerializer(serializers.HyperlinkedModelSerializer):

    """
    Serializer for ApplicationVersion (aka 'image_version')
    """
    # NOTE: Implicitly included via 'fields'
    # id, application
    parent = ImageVersionSummarySerializer()
    #name, change_log, allow_imaging
    licenses = LicenseSerializer(many=True, read_only=True)  # NEW
    membership = serializers.SlugRelatedField(
        slug_field='name',
        read_only=True,
        many=True)  # NEW
    user = UserSummarySerializer(source='created_by')
    identity = IdentitySummarySerializer(source='created_by_identity')
    machines = ProviderMachineRelatedField(many=True)
    start_date = serializers.DateTimeField()
    end_date = serializers.DateTimeField()

    class Meta:
        model = ImageVersion
        view_name = 'api:v2:providermachine-detail'
        fields = ('id', 'parent', 'name', 'change_log',
                  'machines', 'allow_imaging',
                  'licenses', 'membership',
                  'start_date', 'end_date')

Add 'user' and 'identity' attributes to the ImageVersion Details Serializer
Add 'user' and 'identity' attributes to the ImageVersion Details Serializer

  from core.models import ApplicationVersion as ImageVersion
  from rest_framework import serializers
- from api.v2.serializers.summaries import LicenseSerializer
+ from api.v2.serializers.summaries import (
- from api.v2.serializers.summaries import ImageVersionSummarySerializer
+         LicenseSerializer,
+         UserSummarySerializer,
+         IdentitySummarySerializer,
+         ImageVersionSummarySerializer)
  from api.v2.serializers.fields import ProviderMachineRelatedField
  
  
  class ImageVersionSerializer(serializers.HyperlinkedModelSerializer):
  
      """
      Serializer for ApplicationVersion (aka 'image_version')
      """
      # NOTE: Implicitly included via 'fields'
      # id, application
      parent = ImageVersionSummarySerializer()
      #name, change_log, allow_imaging
      licenses = LicenseSerializer(many=True, read_only=True)  # NEW
      membership = serializers.SlugRelatedField(
          slug_field='name',
          read_only=True,
          many=True)  # NEW
+     user = UserSummarySerializer(source='created_by')
+     identity = IdentitySummarySerializer(source='created_by_identity')
      machines = ProviderMachineRelatedField(many=True)
      start_date = serializers.DateTimeField()
      end_date = serializers.DateTimeField()
  
      class Meta:
          model = ImageVersion
          view_name = 'api:v2:providermachine-detail'
          fields = ('id', 'parent', 'name', 'change_log',
                    'machines', 'allow_imaging',
                    'licenses', 'membership',
                    'start_date', 'end_date')
  
Add 'user' and 'identity' attributes to the ImageVersion Details Serializer
## Code Before:
from core.models import ApplicationVersion as ImageVersion
from rest_framework import serializers
from api.v2.serializers.summaries import LicenseSerializer
from api.v2.serializers.summaries import ImageVersionSummarySerializer
from api.v2.serializers.fields import ProviderMachineRelatedField


class ImageVersionSerializer(serializers.HyperlinkedModelSerializer):

    """
    Serializer for ApplicationVersion (aka 'image_version')
    """
    # NOTE: Implicitly included via 'fields'
    # id, application
    parent = ImageVersionSummarySerializer()
    #name, change_log, allow_imaging
    licenses = LicenseSerializer(many=True, read_only=True)  # NEW
    membership = serializers.SlugRelatedField(
        slug_field='name',
        read_only=True,
        many=True)  # NEW
    machines = ProviderMachineRelatedField(many=True)
    start_date = serializers.DateTimeField()
    end_date = serializers.DateTimeField()

    class Meta:
        model = ImageVersion
        view_name = 'api:v2:providermachine-detail'
        fields = ('id', 'parent', 'name', 'change_log',
                  'machines', 'allow_imaging',
                  'licenses', 'membership',
                  'start_date', 'end_date')

## Instruction:
Add 'user' and 'identity' attributes to the ImageVersion Details Serializer
## Code After:
from core.models import ApplicationVersion as ImageVersion
from rest_framework import serializers
from api.v2.serializers.summaries import (
        LicenseSerializer,
        UserSummarySerializer,
        IdentitySummarySerializer,
        ImageVersionSummarySerializer)
from api.v2.serializers.fields import ProviderMachineRelatedField


class ImageVersionSerializer(serializers.HyperlinkedModelSerializer):

    """
    Serializer for ApplicationVersion (aka 'image_version')
    """
    # NOTE: Implicitly included via 'fields'
    # id, application
    parent = ImageVersionSummarySerializer()
    #name, change_log, allow_imaging
    licenses = LicenseSerializer(many=True, read_only=True)  # NEW
    membership = serializers.SlugRelatedField(
        slug_field='name',
        read_only=True,
        many=True)  # NEW
    user = UserSummarySerializer(source='created_by')
    identity = IdentitySummarySerializer(source='created_by_identity')
    machines = ProviderMachineRelatedField(many=True)
    start_date = serializers.DateTimeField()
    end_date = serializers.DateTimeField()

    class Meta:
        model = ImageVersion
        view_name = 'api:v2:providermachine-detail'
        fields = ('id', 'parent', 'name', 'change_log',
                  'machines', 'allow_imaging',
                  'licenses', 'membership',
                  'start_date', 'end_date')
