from rest_framework import serializers as ser

from api.base.serializers import JSONAPISerializer


class PreprintProviderSerializer(JSONAPISerializer):

    filterable_fields = frozenset([
        'name',
        'description',
        'id'
    ])

    name = ser.CharField(required=True)
    description = ser.CharField(required=False)
    id = ser.CharField(max_length=200, source='_id')

    class Meta:
        type_ = 'preprint_providers'

from rest_framework import serializers as ser

from website.settings import API_DOMAIN
from api.base.settings.defaults import API_BASE
from api.base.serializers import JSONAPISerializer, LinksField

class PreprintProviderSerializer(JSONAPISerializer):

    filterable_fields = frozenset([
        'name',
        'description',
        'id'
    ])

    name = ser.CharField(required=True)
    description = ser.CharField(required=False)
    id = ser.CharField(max_length=200, source='_id')

    links = LinksField({
        'self': 'get_absolute_url',
        'preprints': 'preprint_links'
    })

    class Meta:
        type_ = 'preprint_providers'

    def get_absolute_url(self, obj):
        return obj.absolute_api_v2_url

    def preprint_links(self, obj):
        return '{}{}preprint_providers/{}/preprints/'.format(API_DOMAIN, API_BASE, obj._id)

Add links field and related methods to link to a given provider's preprints from the preprint provider serializer
Add links field and related methods to link to a given provider's preprints from the preprint provider serializer

  from rest_framework import serializers as ser
  
+ from website.settings import API_DOMAIN
+ from api.base.settings.defaults import API_BASE
- from api.base.serializers import JSONAPISerializer
+ from api.base.serializers import JSONAPISerializer, LinksField
- 
  
  class PreprintProviderSerializer(JSONAPISerializer):
  
      filterable_fields = frozenset([
          'name',
          'description',
          'id'
      ])
  
      name = ser.CharField(required=True)
      description = ser.CharField(required=False)
      id = ser.CharField(max_length=200, source='_id')
  
+     links = LinksField({
+         'self': 'get_absolute_url',
+         'preprints': 'preprint_links'
+     })
+ 
      class Meta:
          type_ = 'preprint_providers'
  
+     def get_absolute_url(self, obj):
+         return obj.absolute_api_v2_url
+ 
+     def preprint_links(self, obj):
+         return '{}{}preprint_providers/{}/preprints/'.format(API_DOMAIN, API_BASE, obj._id)
+ 
Add links field and related methods to link to a given provider's preprints from the preprint provider serializer
## Code Before:
from rest_framework import serializers as ser

from api.base.serializers import JSONAPISerializer


class PreprintProviderSerializer(JSONAPISerializer):

    filterable_fields = frozenset([
        'name',
        'description',
        'id'
    ])

    name = ser.CharField(required=True)
    description = ser.CharField(required=False)
    id = ser.CharField(max_length=200, source='_id')

    class Meta:
        type_ = 'preprint_providers'

## Instruction:
Add links field and related methods to link to a given provider's preprints from the preprint provider serializer
## Code After:
from rest_framework import serializers as ser

from website.settings import API_DOMAIN
from api.base.settings.defaults import API_BASE
from api.base.serializers import JSONAPISerializer, LinksField

class PreprintProviderSerializer(JSONAPISerializer):

    filterable_fields = frozenset([
        'name',
        'description',
        'id'
    ])

    name = ser.CharField(required=True)
    description = ser.CharField(required=False)
    id = ser.CharField(max_length=200, source='_id')

    links = LinksField({
        'self': 'get_absolute_url',
        'preprints': 'preprint_links'
    })

    class Meta:
        type_ = 'preprint_providers'

    def get_absolute_url(self, obj):
        return obj.absolute_api_v2_url

    def preprint_links(self, obj):
        return '{}{}preprint_providers/{}/preprints/'.format(API_DOMAIN, API_BASE, obj._id)
