2020-02-21 09:41:22 +00:00
|
|
|
import uuid
|
|
|
|
|
2020-02-21 10:32:41 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
# Product in DB vs. product in code
|
|
|
|
# DB:
|
|
|
|
# - need to define params (+param types) in db -> messy?
|
|
|
|
# - get /products/ is easy / automatic
|
|
|
|
#
|
|
|
|
# code
|
|
|
|
# - can have serializer/verification of fields easily in DRF
|
|
|
|
# - can have per product side effects / extra code running
|
|
|
|
# - might (??) make features easier??
|
|
|
|
# - how to setup / query the recurring period (?)
|
|
|
|
# - could get products list via getattr() + re ...Product() classes
|
|
|
|
# -> this could include the url for ordering => /order/vm_snapshot (params)
|
|
|
|
# ---> this would work with urlpatterns
|
|
|
|
|
|
|
|
# Combination: create specific product in DB (?)
|
|
|
|
# - a table per product (?) with 1 entry?
|
|
|
|
|
|
|
|
# Orders
|
|
|
|
# define state in DB
|
|
|
|
# select a price from a product => product might change, order stays
|
|
|
|
# params:
|
|
|
|
# - the product uuid or name (?) => productuuid
|
|
|
|
# - the product parameters => for each feature
|
|
|
|
#
|
|
|
|
|
|
|
|
# logs
|
|
|
|
# Should have a log = ... => 1:n field for most models!
|
2020-02-21 10:32:41 +00:00
|
|
|
|
2020-02-21 09:41:22 +00:00
|
|
|
class Product(models.Model):
|
2020-02-21 23:22:42 +00:00
|
|
|
|
|
|
|
description = ""
|
|
|
|
|
2020-02-21 09:41:22 +00:00
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
name = models.CharField(max_length=256)
|
|
|
|
|
|
|
|
recurring_period = models.CharField(max_length=256,
|
|
|
|
choices = (
|
|
|
|
("per_year", "Per Year"),
|
|
|
|
("per_month", "Per Month"),
|
|
|
|
("per_week", "Per Week"),
|
|
|
|
("per_day", "Per Day"),
|
|
|
|
("per_hour", "Per Hour"),
|
|
|
|
("not_recurring", "Not recurring")
|
|
|
|
),
|
|
|
|
default="not_recurring"
|
|
|
|
)
|
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
# params = [ vmuuid, ... ]
|
|
|
|
# features -> required as defined
|
|
|
|
|
2020-02-21 10:32:41 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "{}".format(self.name)
|
2020-02-21 09:41:22 +00:00
|
|
|
|
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
class VMSnapshotProduct(Product):
|
|
|
|
# need to setup recurring_periodd
|
|
|
|
|
|
|
|
description = "Create snapshot of a VM"
|
|
|
|
|
2020-02-21 09:41:22 +00:00
|
|
|
|
|
|
|
class Feature(models.Model):
|
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
name = models.CharField(max_length=256)
|
|
|
|
|
|
|
|
recurring_price = models.FloatField(default=0)
|
|
|
|
one_time_price = models.FloatField()
|
|
|
|
|
|
|
|
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
2020-02-21 10:32:41 +00:00
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
# params for "cpu": cpu_count -> int
|
|
|
|
# each feature can only have one parameters
|
|
|
|
# could call this "value" and set whether it is user usable
|
|
|
|
# has_value = True/False
|
|
|
|
# value = string -> int (?)
|
|
|
|
# value_int
|
|
|
|
# value_str
|
|
|
|
# value_float
|
|
|
|
|
2020-02-21 10:32:41 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "'{}' - '{}'".format(self.product, self.name)
|
|
|
|
|
|
|
|
|
|
|
|
class Order(models.Model):
|
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
|
|
|
|
owner = models.ForeignKey(get_user_model(),
|
|
|
|
on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
product = models.ForeignKey(Product,
|
|
|
|
on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
|
2020-02-21 23:22:42 +00:00
|
|
|
class VMSnapshotOrder(Order):
|
2020-02-21 10:32:41 +00:00
|
|
|
pass
|