diff --git a/apiserver/apiserver/api/models.py b/apiserver/apiserver/api/models.py index e503a64..0a9517b 100644 --- a/apiserver/apiserver/api/models.py +++ b/apiserver/apiserver/api/models.py @@ -157,9 +157,11 @@ class StatsSpaceActivity(models.Model): class UsageTrack(models.Model): user = models.ForeignKey(User, related_name='usages', blank=True, null=True, on_delete=models.SET_NULL) - username = models.CharField(max_length=64) - devicename = models.CharField(max_length=64) + # member_id = models.IntegerField(blank=True, null=True) # restrict to current users for now + username = models.CharField(max_length=64) # allows us to match non-Spaceport users later + + devicename = models.CharField(max_length=64) start_time = models.DateTimeField(auto_now_add=True) num_seconds = models.IntegerField() diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 1f5cec6..19cf018 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -303,7 +303,10 @@ class AdminSearchSerializer(serializers.Serializer): return serializer.data def get_usages(self, obj): - queryset = obj.user.usages.order_by('-start_time') + if obj.user: + queryset = obj.user.usages.order_by('-start_time') + else: + queryset = [] serializer = UsageSerializer(data=queryset, many=True) serializer.is_valid() return serializer.data