Improve string representation of VMPricing object
This commit is contained in:
parent
d50f282057
commit
3e1d5ba0e2
1 changed files with 14 additions and 2 deletions
|
@ -1,5 +1,9 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VMTemplate(models.Model):
|
class VMTemplate(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -32,14 +36,22 @@ class VMPricing(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name + '-' + 'VAT' if self.vat_inclusive else 'NO_VAT'
|
return self.name + '-' + ' - '.join([
|
||||||
|
'{}/Core'.format(self.cores_unit_price),
|
||||||
|
'{}/GB RAM'.format(self.ram_unit_price),
|
||||||
|
'{}/GB SSD'.format(self.ssd_unit_price),
|
||||||
|
'{}/GB HDD'.format(self.hdd_unit_price),
|
||||||
|
'{}% VAT'.format(self.vat_percentage)
|
||||||
|
if not self.vat_inclusive else 'NO_VAT', ]
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_default_pricing(cls):
|
def get_default_pricing(cls):
|
||||||
""" Returns the default pricing or None """
|
""" Returns the default pricing or None """
|
||||||
try:
|
try:
|
||||||
default_pricing = VMPricing.objects.get(name='default')
|
default_pricing = VMPricing.objects.get(name='default')
|
||||||
except:
|
except Exception as e:
|
||||||
|
logger.error(str(e))
|
||||||
default_pricing = None
|
default_pricing = None
|
||||||
return default_pricing
|
return default_pricing
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue