Skip to content

Commit

Permalink
Merge pull request #56 from HybriD3-database/map_api_systems_dimensio…
Browse files Browse the repository at this point in the history
…nality

Updated serializers.py to map dimensionality properly
  • Loading branch information
uthpalaherath authored Nov 5, 2024
2 parents 13fa3a6 + cf12664 commit 0a8ce3d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions materials/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ class Meta:
)


# Define the DIMENSIONALITIES mapping
DIMENSIONALITIES = {
4: 3,
3: 2.5,
2: 2,
1: 1,
0: 0,
}

# Serializer for System_Stoichiometry (single field for stoichiometry)
class SystemStoichiometrySerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -232,6 +241,7 @@ class Meta:
# SystemSerializer with a custom field for stoichiometry
class SystemSerializer(serializers.ModelSerializer):
stoichiometry = serializers.SerializerMethodField()
dimensionality = serializers.SerializerMethodField()

class Meta:
model = models.System
Expand All @@ -258,3 +268,9 @@ def get_stoichiometry(self, obj):
return stoichiometry_set.stoichiometry
else:
return None # or a default message if no stoichiometry is found

def get_dimensionality(self, obj):
# Map the dimensionality value based on the defined DIMENSIONALITIES mapping
return DIMENSIONALITIES.get(
obj.dimensionality, None
) # Returns None if not in mapping

0 comments on commit 0a8ce3d

Please sign in to comment.