frogress/frog_api/models.py

80 lines
2.5 KiB
Python

from django.db import models
# Example: OOT
class Project(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
slug = models.SlugField(max_length=255, unique=True)
name = models.CharField(max_length=255)
auth_key = models.CharField(max_length=255)
def __str__(self) -> str:
return self.slug
# Example: US 1.0
class Version(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
project = models.ForeignKey(
Project, on_delete=models.CASCADE, related_name="versions"
)
slug = models.SlugField(max_length=255)
name = models.CharField(max_length=255)
def __str__(self) -> str:
return f"{self.project} {self.slug}"
# Example: Actors
class Category(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
version = models.ForeignKey(Version, on_delete=models.CASCADE)
slug = models.SlugField(max_length=255)
name = models.CharField(max_length=255)
class Meta:
verbose_name_plural = "Categories"
def __str__(self) -> str:
return f"{self.version} {self.slug}"
# A snapshot in time of progress, tied to a Category
class Entry(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
timestamp = models.DateTimeField()
git_hash = models.CharField(max_length=40)
class Meta:
verbose_name_plural = "Entries"
ordering = ["-timestamp"]
def __str__(self) -> str:
return f"{self.category} {self.timestamp}"
# A measure (total bytes, bytes matched, functions matched, bytes decompiled, etc) tied to an Entry
class Measure(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
entry = models.ForeignKey(Entry, on_delete=models.CASCADE, related_name="measures")
type = models.CharField(max_length=255)
value = models.IntegerField()
def __str__(self) -> str:
return f"{self.entry} {self.type}: {self.value}"