vbv/server/vbv_lernwelt/shop/models.py

96 lines
3.5 KiB
Python

from django.db import models
class Country(models.Model):
country_id = models.IntegerField(primary_key=True)
name_de = models.CharField(max_length=255)
name_fr = models.CharField(max_length=255)
name_it = models.CharField(max_length=255)
def __str__(self):
return f"{self.name_de} ({self.country_id})"
class Meta:
verbose_name = "Country"
verbose_name_plural = "Countries"
ordering = ["country_id"]
class BillingAddress(models.Model):
"""
Draft of a billing address for a purchase from the shop.
"""
user = models.ForeignKey("core.User", on_delete=models.CASCADE)
# user
first_name = models.CharField(max_length=255, blank=True)
last_name = models.CharField(max_length=255, blank=True)
street = models.CharField(max_length=255, blank=True)
street_number = models.CharField(max_length=255, blank=True)
postal_code = models.CharField(max_length=255, blank=True)
city = models.CharField(max_length=255, blank=True)
country = models.CharField(max_length=255, blank=True)
# company (optional)
company_name = models.CharField(max_length=255, blank=True)
company_street = models.CharField(max_length=255, blank=True)
company_street_number = models.CharField(max_length=255, blank=True)
company_postal_code = models.CharField(max_length=255, blank=True)
company_city = models.CharField(max_length=255, blank=True)
company_country = models.CharField(max_length=255, blank=True)
class Product(models.Model):
sku = models.CharField(max_length=255, primary_key=True)
price = models.IntegerField() # 10_00 = 10.00 CHF
name = models.CharField(max_length=255)
description = models.CharField(max_length=255)
class CheckoutInformation(models.Model):
"""
Immutable checkout information for a purchase from the shop.
"""
user = models.ForeignKey("core.User", on_delete=models.PROTECT)
# immutable product information at time of purchase
product_sku = models.CharField(max_length=255)
product_price = models.IntegerField() # 10_00 = 10.00 CHF
product_name = models.CharField(max_length=255)
product_description = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
state = models.CharField(
max_length=255,
choices=[
("initialized", "initialized"),
("settled", "settled"),
("canceled", "canceled"),
("failed", "failed"),
],
)
invoice_transmitted_at = models.DateTimeField(blank=True, null=True)
transaction_id = models.CharField(max_length=255)
# end user (required)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
street_address = models.CharField(max_length=255)
street_number_address = models.CharField(max_length=255)
postal_code = models.CharField(max_length=255)
city = models.CharField(max_length=255)
country = models.CharField(max_length=255)
# company (optional)
company_name = models.CharField(max_length=255, blank=True)
company_street_address = models.CharField(max_length=255, blank=True)
company_street_number_address = models.CharField(max_length=255, blank=True)
company_postal_code = models.CharField(max_length=255, blank=True)
company_city = models.CharField(max_length=255, blank=True)
company_country = models.CharField(max_length=255, blank=True)