Skip to content

Commit d593c1b

Browse files
committed
Add single item view
1 parent 071b2d5 commit d593c1b

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

opendrift_leeway_webgui/api/v1/serializers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ class LeewaySimulationSerializer(serializers.ModelSerializer):
1313
#: Show username instead of id
1414
username = serializers.ReadOnlyField(source="user.username")
1515

16+
#: Expose the model's error property (last line of traceback)
17+
error = serializers.ReadOnlyField()
18+
19+
#: True once simulation_finished is set
20+
completed = serializers.SerializerMethodField()
21+
22+
def get_completed(self, obj):
23+
"""
24+
:param obj: The simulation instance
25+
:type obj: ~opendrift_leeway_webgui.leeway.models.LeewaySimulation
26+
:rtype: bool
27+
"""
28+
return obj.simulation_finished is not None
29+
1630
class Meta:
1731
"""
1832
Define model and the corresponding fields
@@ -33,6 +47,8 @@ class Meta:
3347
"traceback",
3448
"simulation_started",
3549
"simulation_finished",
50+
"error",
51+
"completed",
3652
]
3753

3854
def create(self, validated_data):

opendrift_leeway_webgui/api/v1/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class LeewaySimulationViewSet(
2525
#: The serializer to use for simulations
2626
serializer_class = LeewaySimulationSerializer
2727

28+
#: Use UUID as the lookup field instead of the integer primary key
29+
lookup_field = "uuid"
30+
2831
def get_queryset(self):
2932
"""
3033
Only return the simulations of the current user

0 commit comments

Comments
 (0)