Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pole-Web
Website
Commits
1511b850
Commit
1511b850
authored
Oct 19, 2020
by
VAN ZUIJLEN Nils
Browse files
Add beginning of models for customization
parent
a9eac444
Changes
2
Hide whitespace changes
Inline
Side-by-side
boutique/migrations/0017_auto_20201019_2351.py
0 → 100644
View file @
1511b850
# 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'
),
),
]
boutique/models.py
View file @
1511b850
...
...
@@ -35,6 +35,32 @@ class Category(models.Model):
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
):
ACTIONS
=
(
(
"no"
,
"Produit"
),
...
...
@@ -77,6 +103,10 @@ class Item(models.Model):
return
True
return
False
@
property
def
has_options
(
self
)
->
bool
:
return
len
(
self
.
options
)
!=
0
@
property
def
post_payment
(
self
)
->
Callable
[[
"OrderItem"
],
None
]:
actions_methods
=
{
...
...
@@ -193,7 +223,7 @@ class Order(models.Model):
for
orderitem
in
self
.
items
.
all
():
orderitem
.
post_payment
()
def
save
(
self
,
*
args
,
**
kwargs
,
)
->
None
:
def
save
(
self
,
*
args
,
**
kwargs
)
->
None
:
if
self
.
ordered
and
self
.
ordered_date
is
None
:
self
.
ordered_date
=
timezone
.
now
()
...
...
@@ -242,6 +272,7 @@ class OrderItem(models.Model):
inscription
=
models
.
OneToOneField
(
Inscription
,
blank
=
True
,
null
=
True
,
default
=
None
,
on_delete
=
models
.
PROTECT
)
chosen_options
=
models
.
ManyToManyField
(
Option
,
blank
=
True
,
default
=
None
)
class
Meta
:
constraints
=
[
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment