Repository: akvo/akvo-rsr

Issue:
project_directory add custom fields to projects
In order to implement filtering at the FE we need to have something like this added to the projects:

```
{
	id,
	name,
	custom_fields: {
		12: [71, 21, 45]
	}
}
```
not sure how the data is stored. If there are no ids for the possible answers we'll have to include the answers themselves.

If you ask why should we filter at the FE:
because we preload all projects at the FE to display the map overview anyway.


Discussion:

Resolving patch:
diff --git a/akvo/rest/serializers/custom_field.py b/akvo/rest/serializers/custom_field.py
--- a/akvo/rest/serializers/custom_field.py
+++ b/akvo/rest/serializers/custom_field.py
@@ -4,9 +4,9 @@
 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
 
+from rest_framework import serializers
 
 from akvo.rsr.models import OrganisationCustomField, ProjectCustomField
-
 from .rsr_serializer import BaseRSRSerializer
 
 
@@ -22,3 +22,18 @@ class ProjectCustomFieldSerializer(BaseRSRSerializer):
     class Meta:
         fields = '__all__'
         model = ProjectCustomField
+
+
+class ProjectDirectoryProjectCustomFieldSerializer(BaseRSRSerializer):
+
+    id = serializers.SerializerMethodField()
+
+    class Meta:
+        fields = ('id', 'name', 'dropdown_selection')
+        model = ProjectCustomField
+
+    def get_id(self, custom_field):
+        try:
+            return OrganisationCustomField.objects.get(name=custom_field.name).pk
+        except OrganisationCustomField.DoesNotExist:
+            return 0
diff --git a/akvo/rest/serializers/project.py b/akvo/rest/serializers/project.py
--- a/akvo/rest/serializers/project.py
+++ b/akvo/rest/serializers/project.py
@@ -15,6 +15,7 @@
 from ..fields import Base64ImageField
 
 from .budget_item import BudgetItemRawSerializer, BudgetItemRawDeepSerializer
+from .custom_field import ProjectDirectoryProjectCustomFieldSerializer
 from .legacy_data import LegacyDataSerializer
 from .link import LinkSerializer
 from .partnership import PartnershipRawSerializer, PartnershipRawDeepSerializer
@@ -108,6 +109,7 @@ class ProjectDirectorySerializer(serializers.ModelSerializer):
     organisation_url = serializers.ReadOnlyField(source='primary_organisation.get_absolute_url')
     organisations = serializers.SerializerMethodField()
     sectors = serializers.SerializerMethodField()
+    dropdown_custom_fields = serializers.SerializerMethodField()
 
     class Meta:
         model = Project
@@ -123,7 +125,8 @@ class Meta:
             'organisation',
             'organisation_url',
             'organisations',
-            'sectors'
+            'sectors',
+            'dropdown_custom_fields',
         )
 
     def get_countries(self, project):
@@ -147,6 +150,10 @@ def get_organisations(self, project):
     def get_sectors(self, project):
         return [sector.sector_code for sector in project.sectors.distinct()]
 
+    def get_dropdown_custom_fields(self, project):
+        custom_fields = project.custom_fields.filter(type='dropdown')
+        return ProjectDirectoryProjectCustomFieldSerializer(custom_fields, many=True).data
+
 
 class ProjectIatiExportSerializer(BaseRSRSerializer):
 


Test patch: