add model for compute plans

This commit is contained in:
Tobias Brunner 2025-05-20 11:26:52 +02:00
parent 1347f9c72a
commit cc5307a723
Signed by: tobru
SSH key fingerprint: SHA256:kOXg1R6c11XW3/Pt9dbLdQvOJGFAy+B2K6v6PtRWBGQ
3 changed files with 115 additions and 4 deletions

View file

@ -3,6 +3,7 @@ from django.core.exceptions import ValidationError
from django.urls import reverse
from django.utils.text import slugify
from django_prose_editor.fields import ProseEditorField
from django.core.validators import URLValidator
def validate_image_size(value):
@ -288,8 +289,6 @@ class ExternalLinkOffering(models.Model):
return f"{self.description} ({self.url})"
def clean(self):
from django.core.validators import URLValidator
validate = URLValidator()
try:
validate(self.url)
@ -316,8 +315,6 @@ class ExternalLink(models.Model):
return f"{self.description} ({self.url})"
def clean(self):
from django.core.validators import URLValidator
validate = URLValidator()
try:
validate(self.url)
@ -357,3 +354,33 @@ class WebsiteFaq(models.Model):
def __str__(self):
return self.question
class ComputePlan(models.Model):
name = models.CharField(max_length=200)
vcpus = models.FloatField(help_text="Number of available vCPUs")
ram = models.FloatField(help_text="Amount of RAM available")
cpu_mem_ratio = models.FloatField(
help_text="vCPU to Memory ratio. How much vCPU per GiB RAM is available?"
)
price_chf = models.FloatField(help_text="Plan price in CHF excl. VAT")
price_eur = models.FloatField(
help_text="Plan price in EUR excl. VAT", blank=True, null=True
)
price_usd = models.FloatField(
help_text="Plan price in USD excl. VAT", blank=True, null=True
)
active = models.BooleanField(default=True, help_text="Is the plan active?")
cloud_provider = models.ForeignKey(
CloudProvider, on_delete=models.CASCADE, related_name="compute_plans"
)
valid_from = models.DateTimeField(blank=True, null=True)
valid_to = models.DateTimeField(blank=True, null=True)
class Meta:
ordering = ["price_chf"]
def __str__(self):
return self.name