forked from uncloud/uncloud
Make recurring_period an Enum, VMProduct a Product, initial wire for
order
This commit is contained in:
parent
1dd3324275
commit
b2fe5014d8
6 changed files with 113 additions and 24 deletions
|
|
@ -2,7 +2,7 @@ from django.db import models
|
|||
from django.contrib.auth import get_user_model
|
||||
import uuid
|
||||
|
||||
from uncloud_pay.models import Product
|
||||
from uncloud_pay.models import Product, RecurringPeriod
|
||||
|
||||
|
||||
class VMHost(models.Model):
|
||||
|
|
@ -32,22 +32,25 @@ class VMHost(models.Model):
|
|||
)
|
||||
|
||||
|
||||
class VMProduct(models.Model):
|
||||
uuid = models.UUIDField(primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
editable=False)
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE,
|
||||
editable=False)
|
||||
class VMProduct(Product):
|
||||
vmhost = models.ForeignKey(VMHost,
|
||||
on_delete=models.CASCADE,
|
||||
editable=False,
|
||||
blank=True,
|
||||
null=True)
|
||||
|
||||
description = "Virtual Machine"
|
||||
cores = models.IntegerField()
|
||||
ram_in_gb = models.FloatField()
|
||||
|
||||
@property
|
||||
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
||||
if recurring_period == RecurringPeriod.PER_MONTH:
|
||||
# TODO: move magic numbers in variables
|
||||
return self.cores * 3 + self.ram_in_gb * 2
|
||||
else:
|
||||
raise Exception('Invalid recurring period for VM Product pricing.')
|
||||
|
||||
|
||||
class VMWithOSProduct(VMProduct):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue