forked from uncloud/uncloud
Define custom fields and serializer for MatrixServiceProduct
This commit is contained in:
parent
eaa483e018
commit
af1265003e
4 changed files with 17 additions and 3 deletions
|
@ -163,5 +163,9 @@ class Product(models.Model):
|
||||||
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
||||||
pass # To be implemented in child.
|
pass # To be implemented in child.
|
||||||
|
|
||||||
|
@property
|
||||||
|
def setup_fee(self):
|
||||||
|
return 0
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
|
@ -12,9 +12,9 @@ class VMHostSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class VMProductSerializer(serializers.HyperlinkedModelSerializer):
|
class VMProductSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VMProduct
|
model = VMProduct
|
||||||
fields = ['uuid', 'description', 'order', 'owner', 'status', 'name', \
|
fields = ['uuid', 'order', 'owner', 'status', 'name', \
|
||||||
'cores', 'ram_in_gb']
|
'cores', 'ram_in_gb']
|
||||||
read_only_fields = ['uuid', 'description', 'order', 'owner', 'status']
|
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
||||||
|
|
||||||
class VMSnapshotProductSerializer(serializers.ModelSerializer):
|
class VMSnapshotProductSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -9,12 +9,18 @@ class MatrixServiceProduct(Product):
|
||||||
setup_fee = 30
|
setup_fee = 30
|
||||||
|
|
||||||
description = "Managed Matrix HomeServer"
|
description = "Managed Matrix HomeServer"
|
||||||
|
|
||||||
|
# Specific to Matrix-as-a-Service
|
||||||
vm = models.ForeignKey(
|
vm = models.ForeignKey(
|
||||||
VMProduct, on_delete=models.CASCADE
|
VMProduct, on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
|
domain = models.CharField(max_length=255, default='domain.tld')
|
||||||
|
|
||||||
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
||||||
if recurring_period == RecurringPeriod.PER_MONTH:
|
if recurring_period == RecurringPeriod.PER_MONTH:
|
||||||
return monthly_managment_fee + vm.recurring_price(RecurringPeriod.PER_MONTH)
|
return monthly_managment_fee + vm.recurring_price(RecurringPeriod.PER_MONTH)
|
||||||
else:
|
else:
|
||||||
raise Exception('Invalid recurring period for VM Product pricing.')
|
raise Exception('Invalid recurring period for VM Product pricing.')
|
||||||
|
|
||||||
|
def setup_fee(self):
|
||||||
|
return setup_fee
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import MatrixServiceProduct
|
from .models import MatrixServiceProduct
|
||||||
|
from uncloud_vm.serializers import VMProductSerializer
|
||||||
|
|
||||||
class MatrixServiceProductSerializer(serializers.ModelSerializer):
|
class MatrixServiceProductSerializer(serializers.ModelSerializer):
|
||||||
|
vm = VMProductSerializer()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MatrixServiceProduct
|
model = MatrixServiceProduct
|
||||||
fields = '__all__'
|
fields = ['uuid', 'order', 'owner', 'status', 'vm', 'domain']
|
||||||
|
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
||||||
|
|
Loading…
Reference in a new issue