Commit 1511b850 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Add beginning of models for customization

parent a9eac444
# Generated by Django 2.2.16 on 2020-10-19 21:51
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('boutique', '0016_auto_20200904_2132'),
]
operations = [
migrations.CreateModel(
name='OptionGroup',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('type', models.CharField(choices=[('multiple_choice', 'Choix multiple'), ('free_text', 'Texte libre'), ('multiple_choice_other', 'Choix multiple ou texte libre'), ('boolean', 'Oui/Non')], max_length=25)),
('required', models.BooleanField(default=True)),
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='boutique.Item')),
],
),
migrations.CreateModel(
name='Option',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.CharField(max_length=255)),
('original', models.BooleanField()),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='boutique.OptionGroup')),
],
),
migrations.AddField(
model_name='orderitem',
name='chosen_options',
field=models.ManyToManyField(blank=True, default=None, to='boutique.Option'),
),
]
...@@ -35,6 +35,32 @@ class Category(models.Model): ...@@ -35,6 +35,32 @@ class Category(models.Model):
return self.name return self.name
class OptionGroup(models.Model):
TYPES = (
("multiple_choice", "Choix multiple"),
("free_text", "Texte libre"),
("multiple_choice_other", "Choix multiple ou texte libre"),
("boolean", "Oui/Non"),
)
name = models.CharField(max_length=255)
type = models.CharField(max_length=25, choices=TYPES)
required = models.BooleanField(default=True)
item = models.ForeignKey("Item", on_delete=models.CASCADE, related_name="options")
def __str__(self) -> str:
return self.name
class Option(models.Model):
group = models.ForeignKey(OptionGroup, on_delete=models.CASCADE)
value = models.CharField(max_length=255)
original = models.BooleanField()
def __str__(self) -> str:
return f'Option "{self.value}" of {self.group}'
class Item(models.Model): class Item(models.Model):
ACTIONS = ( ACTIONS = (
("no", "Produit"), ("no", "Produit"),
...@@ -77,6 +103,10 @@ class Item(models.Model): ...@@ -77,6 +103,10 @@ class Item(models.Model):
return True return True
return False return False
@property
def has_options(self) -> bool:
return len(self.options) != 0
@property @property
def post_payment(self) -> Callable[["OrderItem"], None]: def post_payment(self) -> Callable[["OrderItem"], None]:
actions_methods = { actions_methods = {
...@@ -193,7 +223,7 @@ class Order(models.Model): ...@@ -193,7 +223,7 @@ class Order(models.Model):
for orderitem in self.items.all(): for orderitem in self.items.all():
orderitem.post_payment() orderitem.post_payment()
def save(self, *args, **kwargs,) -> None: def save(self, *args, **kwargs) -> None:
if self.ordered and self.ordered_date is None: if self.ordered and self.ordered_date is None:
self.ordered_date = timezone.now() self.ordered_date = timezone.now()
...@@ -242,6 +272,7 @@ class OrderItem(models.Model): ...@@ -242,6 +272,7 @@ class OrderItem(models.Model):
inscription = models.OneToOneField( inscription = models.OneToOneField(
Inscription, blank=True, null=True, default=None, on_delete=models.PROTECT Inscription, blank=True, null=True, default=None, on_delete=models.PROTECT
) )
chosen_options = models.ManyToManyField(Option, blank=True, default=None)
class Meta: class Meta:
constraints = [ constraints = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment