from rest_framework import serializers as ser

from api.base.serializers import JSONAPISerializer, RelationshipField, LinksField

class InstitutionSerializer(JSONAPISerializer):

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

    name = ser.CharField(read_only=True)
    id = ser.CharField(read_only=True, source='_id')
    logo_path = ser.CharField(read_only=True)
    auth_url = ser.CharField(read_only=True)
    links = LinksField({'self': 'get_api_url', })

    nodes = RelationshipField(
        related_view='institutions:institution-nodes',
        related_view_kwargs={'institution_id': '<pk>'},
    )

    registrations = RelationshipField(
        related_view='institutions:institution-registrations',
        related_view_kwargs={'institution_id': '<pk>'}
    )

    users = RelationshipField(
        related_view='institutions:institution-users',
        related_view_kwargs={'institution_id': '<pk>'}
    )

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

    class Meta:
        type_ = 'institutions'

from rest_framework import serializers as ser

from api.base.serializers import JSONAPISerializer, RelationshipField, LinksField

class InstitutionSerializer(JSONAPISerializer):

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

    name = ser.CharField(read_only=True)
    id = ser.CharField(read_only=True, source='_id')
    logo_path = ser.CharField(read_only=True)
    auth_url = ser.CharField(read_only=True)
    links = LinksField({'self': 'get_api_url', })

    nodes = RelationshipField(
        related_view='institutions:institution-nodes',
        related_view_kwargs={'institution_id': '<pk>'},
    )

    registrations = RelationshipField(
        related_view='institutions:institution-registrations',
        related_view_kwargs={'institution_id': '<pk>'}
    )

    users = RelationshipField(
        related_view='institutions:institution-users',
        related_view_kwargs={'institution_id': '<pk>'}
    )

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

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

    class Meta:
        type_ = 'institutions'

Add get_absolute_url method to institutions
Add get_absolute_url method to institutions
