diff --git a/hosting/admin.py b/hosting/admin.py index 4f2f15e1..c38fa8d0 100644 --- a/hosting/admin.py +++ b/hosting/admin.py @@ -4,8 +4,9 @@ from django.core.urlresolvers import reverse from utils.mailer import BaseEmail -from .models import HostingOrder, HostingBill +from .models import HostingOrder, HostingBill, HostingPlan admin.site.register(HostingOrder) admin.site.register(HostingBill) +admin.site.register(HostingPlan) diff --git a/hosting/migrations/0040_hostingplan.py b/hosting/migrations/0040_hostingplan.py new file mode 100644 index 00000000..cb48ccd6 --- /dev/null +++ b/hosting/migrations/0040_hostingplan.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2017-05-13 11:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hosting', '0039_hostingorder_price'), + ] + + operations = [ + migrations.CreateModel( + name='HostingPlan', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('disk_size', models.FloatField(default=0.0)), + ('cpu_cores', models.FloatField(default=0.0)), + ('memory', models.FloatField(default=0.0)), + ], + ), + ] diff --git a/hosting/models.py b/hosting/models.py index 6be6c246..f8f180a5 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -21,6 +21,31 @@ from .managers import VMPlansManager logger = logging.getLogger(__name__) +class HostingPlan(models.Model): + disk_size = models.FloatField(default=0.0) + cpu_cores = models.FloatField(default=0.0) + memory = models.FloatField(default=0.0) + + def serialize(self): + return { + 'id': self.id, + 'cpu':self.cpu_cores, + 'memory': self.memory, + 'disk_size': self.disk_size, + 'price': self.price(), + } + + @classmethod + def get_serialized_configs(cls): + return [cfg.serialize() + for cfg in cls.objects.all()] + + def price(self): + price = self.disk_size * 0.2 + price += self.cpu_cores * 5 + price += self.memory * 2 + return price + class HostingOrder(AssignPermissionsMixin, models.Model): ORDER_APPROVED_STATUS = 'Approved' diff --git a/hosting/templates/hosting/bill_detail.html b/hosting/templates/hosting/bill_detail.html index 9e92d0e9..e34b2f11 100644 --- a/hosting/templates/hosting/bill_detail.html +++ b/hosting/templates/hosting/bill_detail.html @@ -4,7 +4,7 @@ {% block content %}