from rest_framework import serializers, viewsets

from document.models import Document, Kamerstuk, Dossier


class DossierSerializer(serializers.HyperlinkedModelSerializer):
    documents = serializers.HyperlinkedRelatedField(read_only=True,
                                                    view_name='document-detail',
                                                    many=True)

    class Meta:
        model = Dossier
        fields = ('id', 'dossier_id', 'title', 'documents')


class DossierViewSet(viewsets.ModelViewSet):
    queryset = Dossier.objects.all()
    serializer_class = DossierSerializer


class DocumentSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Document
        fields = ('id', 'dossier', 'raw_type', 'raw_title', 'publisher', 'date_published', 'document_url')


class DocumentViewSet(viewsets.ModelViewSet):
    queryset = Document.objects.all()
    serializer_class = DocumentSerializer


class KamerstukSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Kamerstuk
        fields = ('id', 'document', 'id_main', 'id_sub', 'type_short', 'type_long')


class KamerstukViewSet(viewsets.ModelViewSet):
    queryset = Kamerstuk.objects.all()
    serializer_class = KamerstukSerializer


from rest_framework import serializers, viewsets

from document.models import Document, Kamerstuk, Dossier


class DossierSerializer(serializers.HyperlinkedModelSerializer):
    documents = serializers.HyperlinkedRelatedField(read_only=True,
                                                    view_name='document-detail',
                                                    many=True)

    kamerstukken = serializers.HyperlinkedRelatedField(read_only=True,
                                                    view_name='kamerstuk-detail',
                                                    many=True)

    class Meta:
        model = Dossier
        fields = ('id', 'dossier_id', 'title', 'kamerstukken', 'documents')


class DossierViewSet(viewsets.ModelViewSet):
    queryset = Dossier.objects.all()
    serializer_class = DossierSerializer


class DocumentSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Document
        fields = ('id', 'dossier', 'raw_type', 'raw_title', 'publisher', 'date_published', 'document_url')


class DocumentViewSet(viewsets.ModelViewSet):
    queryset = Document.objects.all()
    serializer_class = DocumentSerializer


class KamerstukSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Kamerstuk
        fields = ('id', 'document', 'id_main', 'id_sub', 'type_short', 'type_long')


class KamerstukViewSet(viewsets.ModelViewSet):
    queryset = Kamerstuk.objects.all()
    serializer_class = KamerstukSerializer


Add kamerstukken to dossier API
Add kamerstukken to dossier API

  from rest_framework import serializers, viewsets
  
  from document.models import Document, Kamerstuk, Dossier
  
  
  class DossierSerializer(serializers.HyperlinkedModelSerializer):
      documents = serializers.HyperlinkedRelatedField(read_only=True,
                                                      view_name='document-detail',
                                                      many=True)
  
+     kamerstukken = serializers.HyperlinkedRelatedField(read_only=True,
+                                                     view_name='kamerstuk-detail',
+                                                     many=True)
+ 
      class Meta:
          model = Dossier
-         fields = ('id', 'dossier_id', 'title', 'documents')
+         fields = ('id', 'dossier_id', 'title', 'kamerstukken', 'documents')
  
  
  class DossierViewSet(viewsets.ModelViewSet):
      queryset = Dossier.objects.all()
      serializer_class = DossierSerializer
  
  
  class DocumentSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = Document
          fields = ('id', 'dossier', 'raw_type', 'raw_title', 'publisher', 'date_published', 'document_url')
  
  
  class DocumentViewSet(viewsets.ModelViewSet):
      queryset = Document.objects.all()
      serializer_class = DocumentSerializer
  
  
  class KamerstukSerializer(serializers.HyperlinkedModelSerializer):
      class Meta:
          model = Kamerstuk
          fields = ('id', 'document', 'id_main', 'id_sub', 'type_short', 'type_long')
  
  
  class KamerstukViewSet(viewsets.ModelViewSet):
      queryset = Kamerstuk.objects.all()
      serializer_class = KamerstukSerializer
  
  
Add kamerstukken to dossier API
## Code Before:
from rest_framework import serializers, viewsets

from document.models import Document, Kamerstuk, Dossier


class DossierSerializer(serializers.HyperlinkedModelSerializer):
    documents = serializers.HyperlinkedRelatedField(read_only=True,
                                                    view_name='document-detail',
                                                    many=True)

    class Meta:
        model = Dossier
        fields = ('id', 'dossier_id', 'title', 'documents')


class DossierViewSet(viewsets.ModelViewSet):
    queryset = Dossier.objects.all()
    serializer_class = DossierSerializer


class DocumentSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Document
        fields = ('id', 'dossier', 'raw_type', 'raw_title', 'publisher', 'date_published', 'document_url')


class DocumentViewSet(viewsets.ModelViewSet):
    queryset = Document.objects.all()
    serializer_class = DocumentSerializer


class KamerstukSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Kamerstuk
        fields = ('id', 'document', 'id_main', 'id_sub', 'type_short', 'type_long')


class KamerstukViewSet(viewsets.ModelViewSet):
    queryset = Kamerstuk.objects.all()
    serializer_class = KamerstukSerializer


## Instruction:
Add kamerstukken to dossier API
## Code After:
from rest_framework import serializers, viewsets

from document.models import Document, Kamerstuk, Dossier


class DossierSerializer(serializers.HyperlinkedModelSerializer):
    documents = serializers.HyperlinkedRelatedField(read_only=True,
                                                    view_name='document-detail',
                                                    many=True)

    kamerstukken = serializers.HyperlinkedRelatedField(read_only=True,
                                                    view_name='kamerstuk-detail',
                                                    many=True)

    class Meta:
        model = Dossier
        fields = ('id', 'dossier_id', 'title', 'kamerstukken', 'documents')


class DossierViewSet(viewsets.ModelViewSet):
    queryset = Dossier.objects.all()
    serializer_class = DossierSerializer


class DocumentSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Document
        fields = ('id', 'dossier', 'raw_type', 'raw_title', 'publisher', 'date_published', 'document_url')


class DocumentViewSet(viewsets.ModelViewSet):
    queryset = Document.objects.all()
    serializer_class = DocumentSerializer


class KamerstukSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Kamerstuk
        fields = ('id', 'document', 'id_main', 'id_sub', 'type_short', 'type_long')


class KamerstukViewSet(viewsets.ModelViewSet):
    queryset = Kamerstuk.objects.all()
    serializer_class = KamerstukSerializer

