Fix usages bug when member's not a Spaceport user
This commit is contained in:
parent
74dfdc6c06
commit
a0c9c52475
|
@ -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()
|
||||
|
||||
|
|
|
@ -303,7 +303,10 @@ class AdminSearchSerializer(serializers.Serializer):
|
|||
return serializer.data
|
||||
|
||||
def get_usages(self, obj):
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user