This repository has been archived on 2023-02-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-my-data/mydata_benchmarks/models.py

37 lines
1.5 KiB
Python

from urllib.parse import urljoin
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.postgres.fields import JSONField
from django.db import models
class Benchmark(models.Model):
"""The result of a benchmark run on the Benchmark Client."""
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, related_name='benchmarks')
benchmark_id = models.CharField(max_length=48, editable=False, db_index=True)
manage_id = models.CharField(max_length=48, editable=False)
date_created = models.DateTimeField(auto_now_add=True)
data_raw = JSONField(editable=False) # The original result of a benchmark
class Meta:
ordering = ('-date_created',)
def get_absolute_url(self) -> str:
"""Return absolute URL to the benchmark on OpenData."""
return urljoin(settings.BLENDER_OPENDATA['BASE_URL'], f'benchmark/{self.benchmark_id}')
class ClientToken(models.Model):
"""Used by Benchmark Client to submit data as a User."""
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='client_tokens')
token = models.CharField(max_length=200, db_index=True)
hostname = models.CharField(max_length=100, blank=True) # The hostname of the Benchmark client
date_created = models.DateTimeField(auto_now_add=True)
# TODO(fsiddi) add a date_last_used to show the activity of a client in the UI
is_valid = models.BooleanField(default=True)
class Meta:
ordering = ('-date_created',)
verbose_name = 'Client Token'