forked from uncloud/uncloud
Add ProductOrderView
This commit is contained in:
parent
69e564cba6
commit
d3b6d28ae6
8 changed files with 82 additions and 6 deletions
|
@ -12,3 +12,9 @@ machine. Use `kubectl get nodes` to verify minikube is up and running.
|
|||
* `SECRET_KEY`
|
||||
* `DEBUG`
|
||||
* `DATABASE`
|
||||
|
||||
## Versions
|
||||
|
||||
#### 3.0.0
|
||||
|
||||
* Introduce ProductOrderView
|
||||
|
|
|
@ -4,6 +4,7 @@ from .models import *
|
|||
|
||||
|
||||
for m in [
|
||||
Currency,
|
||||
Order,
|
||||
PricePerTime,
|
||||
Product,
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 4.0 on 2022-01-02 20:04
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0002_auto_20220102_1953'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='product',
|
||||
name='resources',
|
||||
field=models.ManyToManyField(blank=True, to='app.Resource'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='resource',
|
||||
name='unit',
|
||||
field=models.CharField(max_length=128),
|
||||
),
|
||||
]
|
19
uncloud_v3/app/migrations/0004_auto_20220102_2020.py
Normal file
19
uncloud_v3/app/migrations/0004_auto_20220102_2020.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.0 on 2022-01-02 20:20
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
def gen_currencies(apps, schema_editor):
|
||||
Currency = apps.get_model('app', 'Currency')
|
||||
|
||||
Currency.objects.get_or_create(name="Swiss Franc",
|
||||
short_name="CHF")
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0003_alter_product_resources_alter_resource_unit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(gen_currencies),
|
||||
]
|
|
@ -7,7 +7,7 @@ class Currency(models.Model):
|
|||
short_name = models.CharField(max_length=3, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} {self.short_name}"
|
||||
return f"{self.name} ({self.short_name})"
|
||||
|
||||
|
||||
class TimeFrame(models.Model):
|
||||
|
@ -31,7 +31,8 @@ class TimeFrame(models.Model):
|
|||
return f"{days} days {hours} hours {secs} seconds"
|
||||
|
||||
def __str__(self):
|
||||
return "{} ({})".format(self.name, self.secs_to_name(self.seconds))
|
||||
#return "{} ({})".format(self.name, self.secs_to_name(self.seconds))
|
||||
return f"{self.name}"
|
||||
|
||||
class PricePerTime(models.Model):
|
||||
timeframe = models.ForeignKey(TimeFrame, on_delete=models.CASCADE)
|
||||
|
@ -43,7 +44,7 @@ class PricePerTime(models.Model):
|
|||
|
||||
class Resource(models.Model):
|
||||
name = models.CharField(max_length=128, unique=True) # CPU, RAM
|
||||
unit = models.CharField(max_length=128, unique=True) # Count, GB
|
||||
unit = models.CharField(max_length=128) # Count, GB
|
||||
minimum_units = models.FloatField(null=True, blank=True) # might have min
|
||||
maximum_units = models.FloatField(null=True, blank=True) # might have max
|
||||
step_size = models.FloatField(default=1) # might/must step size
|
||||
|
@ -51,7 +52,22 @@ class Resource(models.Model):
|
|||
price_per_time = models.ManyToManyField(PricePerTime, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}: {self.minimum_units}-{self.maximum_units} (+/-){self.step_size} {self.unit}"
|
||||
if self.minimum_units:
|
||||
minimum = self.minimum_units
|
||||
else:
|
||||
minimum = "No minimum"
|
||||
if self.maximum_units:
|
||||
maximum = self.maximum_units
|
||||
else:
|
||||
maximum = "No maximum"
|
||||
|
||||
pricing = []
|
||||
for price in self.price_per_time.all():
|
||||
pricing.append(f"{price.price}{price.currency.short_name}/{price.timeframe}")
|
||||
|
||||
pricing = ", ".join(pricing)
|
||||
|
||||
return f"{self.name}: {minimum}-{maximum} (+/-){self.step_size} {self.unit} ({pricing})"
|
||||
|
||||
class ResourceOrder(models.Model):
|
||||
"""
|
||||
|
@ -72,7 +88,7 @@ class Product(models.Model):
|
|||
# textconfig = models.ManyToManyField(ProductTextConfiguration)
|
||||
# textfieldconfig = models.ManyToManyField(ProductTextFieldConfiguration)
|
||||
|
||||
resources = models.ManyToManyField(Resource)
|
||||
resources = models.ManyToManyField(Resource, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
4
uncloud_v3/app/templates/app/productorder_form.html
Normal file
4
uncloud_v3/app/templates/app/productorder_form.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
<form method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
|
@ -1,3 +1,8 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from django.views.generic.edit import CreateView
|
||||
from .models import ProductOrder
|
||||
|
||||
class ProductOrderView(CreateView):
|
||||
model = ProductOrder
|
||||
fields = ['product', 'resources' ]
|
||||
|
|
|
@ -15,7 +15,9 @@ Including another URLconf
|
|||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from app import views as appviews
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('order', appviews.ProductOrderView.as_view())
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue