From 76c9b20cc9534e603b6caa6df59607c5eda706bd Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 9 Apr 2018 21:34:09 +0200 Subject: [PATCH] Add VMPricing init migration --- .../migrations/0020_auto_20180409_1928.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 datacenterlight/migrations/0020_auto_20180409_1928.py diff --git a/datacenterlight/migrations/0020_auto_20180409_1928.py b/datacenterlight/migrations/0020_auto_20180409_1928.py new file mode 100644 index 00000000..9a659acc --- /dev/null +++ b/datacenterlight/migrations/0020_auto_20180409_1928.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-04-09 19:28 +from __future__ import unicode_literals + +from django.db import migrations + +DEFAULT_VMPRICING_NAME='default' + + +def create_default_pricing(apps, schema_editor): + """ + Create default pricing + :param apps: + :param schema_editor: + :return: + """ + VMPricing = apps.get_model('datacenterlight', 'VMPricing') + if not VMPricing.objects.count(): + vm_pricing = VMPricing( + name=DEFAULT_VMPRICING_NAME, + vat_inclusive=True, + cores_unit_price=5, + ram_unit_price=2, + ssd_unit_price=0.6, + hdd_unit_price=0.1, + ) + vm_pricing.save() + + +def undo_vm_pricing(apps, schema_editor): + """Deleting all entries for this model""" + + VMPricing = apps.get_model("datacenterlight", "VMPricing") + VMPricing.objects.all().delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('datacenterlight', '0019_auto_20180409_1923'), + ] + + operations = [ + migrations.RunPython( + create_default_pricing, + reverse_code=undo_vm_pricing + ), + ]