From 1e0f1cd49625b5ca91d4a58cd7b1844e2747ebe8 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Sat, 28 Jan 2017 22:39:56 -0600 Subject: [PATCH] Include available states to transition to. --- bikeshop_project/bike/models.py | 12 ++++++++++-- bikeshop_project/bike/serializers.py | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bikeshop_project/bike/models.py b/bikeshop_project/bike/models.py index 2c0689c..6d6fc3d 100644 --- a/bikeshop_project/bike/models.py +++ b/bikeshop_project/bike/models.py @@ -78,8 +78,9 @@ class Bike(models.Model): return self.stolen is False and self.cpic_searched_at is not None and self.serial_number is not None def can_claim(self): - return self.claimed_by is None or not (self.claimed_by is not None and self.last_worked_on > timezone.now() - timedelta( - weeks=4)) or self.last_worked_on is None + return self.claimed_by is None or not ( + self.claimed_by is not None and self.last_worked_on > timezone.now() - timedelta( + weeks=4)) or self.last_worked_on is None def can_purchase(self): if self.claimed_by: @@ -122,3 +123,10 @@ class Bike(models.Model): @transition(field=state, source=[BikeState.ASSESSED, BikeState.RECEIVED], conditions=[can_transfer_to_police]) def transfer_to_police(self): pass + + @property + def available_states(self): + states = [state_transition.name + for state_transition in self.get_available_state_transitions()] + + return states diff --git a/bikeshop_project/bike/serializers.py b/bikeshop_project/bike/serializers.py index 398322f..aea242f 100644 --- a/bikeshop_project/bike/serializers.py +++ b/bikeshop_project/bike/serializers.py @@ -10,3 +10,4 @@ class BikeSerializer(serializers.HyperlinkedModelSerializer): created_at = serializers.ReadOnlyField() state = serializers.ReadOnlyField() + available_states = serializers.ReadOnlyField()