Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
WSR Website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sofiane Lasri
WSR Website
Commits
5f33c124
Commit
5f33c124
authored
2 years ago
by
Sofiane Lasri
Browse files
Options
Downloads
Patches
Plain Diff
Création ddu modèle RaceType
parent
9735ce6a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
WSR/migrations/0017_racetype_alter_race_type.py
+46
-0
46 additions, 0 deletions
WSR/migrations/0017_racetype_alter_race_type.py
WSR/models.py
+10
-13
10 additions, 13 deletions
WSR/models.py
with
56 additions
and
13 deletions
WSR/migrations/0017_racetype_alter_race_type.py
0 → 100644
+
46
−
0
View file @
5f33c124
from
django.db
import
migrations
,
models
def
create_race_types
(
apps
,
schema_editor
):
Race
=
apps
.
get_model
(
'
WSR
'
,
'
Race
'
)
RaceType
=
apps
.
get_model
(
'
WSR
'
,
'
RaceType
'
)
race_types
=
set
([
race
.
type
for
race
in
Race
.
objects
.
all
()])
with
schema_editor
.
connection
.
cursor
()
as
cursor
:
for
race_type
in
race_types
:
instance
,
created
=
RaceType
.
objects
.
get_or_create
(
name
=
race_type
)
if
created
:
instance
.
description
=
"
Description du type de course
"
instance
.
save
()
cursor
.
execute
(
"
UPDATE WSR_race SET type = %s WHERE type = %s
"
,
[
instance
.
id
,
race_type
]
)
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
WSR
'
,
'
0016_vehicle_image_alter_driver_vehicle_and_more
'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'
RaceType
'
,
fields
=
[
(
'
id
'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'
ID
'
)),
(
'
name
'
,
models
.
CharField
(
max_length
=
100
)),
(
'
description
'
,
models
.
TextField
(
blank
=
True
,
default
=
''
)),
(
'
font_awesome_icon
'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
64
)),
(
'
image
'
,
models
.
ImageField
(
blank
=
True
,
default
=
''
,
upload_to
=
'
racetypes
'
,
verbose_name
=
"
Image d
'
illustration
"
)),
],
),
migrations
.
RunPython
(
create_race_types
),
migrations
.
AlterField
(
model_name
=
'
race
'
,
name
=
'
type
'
,
field
=
models
.
ForeignKey
(
on_delete
=
models
.
deletion
.
CASCADE
,
to
=
'
WSR.RaceType
'
),
),
]
This diff is collapsed.
Click to expand it.
WSR/models.py
+
10
−
13
View file @
5f33c124
...
...
@@ -27,20 +27,17 @@ class Vehicle(models.Model):
def
__str__
(
self
):
return
f
"
{
self
.
brand
}
{
self
.
model
}
"
class
RaceType
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
description
=
models
.
TextField
(
default
=
""
,
blank
=
True
)
font_awesome_icon
=
models
.
CharField
(
max_length
=
64
,
default
=
""
,
blank
=
True
)
image
=
models
.
ImageField
(
upload_to
=
'
racetypes
'
,
default
=
""
,
blank
=
True
,
verbose_name
=
"
Image d
'
illustration
"
)
def
__str__
(
self
):
return
self
.
name
class
Race
(
models
.
Model
):
class
RaceType
(
models
.
TextChoices
):
CHAMPIONSHIP
=
"
championship
"
SINGLE_RACE
=
"
single_race
"
FACE_TO_FACE
=
"
face_to_face
"
OVERTAKING
=
"
overtaking
"
AGAINST_TIME
=
"
against_time
"
ELIMINATION
=
"
elimination
"
ENDURANCE
=
"
endurance
"
TOUGE
=
"
touge
"
CHECKPOINT
=
"
checkpoint
"
DRIFT
=
"
drift
"
class
Race
(
models
.
Model
):
class
RaceParticipationType
(
models
.
TextChoices
):
INVITATION
=
"
invitation
"
PARTICIPATION
=
"
participation
"
...
...
@@ -85,7 +82,7 @@ class Race(models.Model):
finishing_position
=
models
.
PositiveIntegerField
(
verbose_name
=
"
Position d
'
arrivée
"
)
season
=
models
.
ForeignKey
(
Season
,
on_delete
=
models
.
CASCADE
)
image
=
models
.
ImageField
(
upload_to
=
'
race_images
'
,
verbose_name
=
"
Image d
'
illustration
"
)
type
=
models
.
CharField
(
max_length
=
100
,
choices
=
RaceType
.
choices
,
default
=
RaceType
.
SINGLE_RAC
E
)
type
=
models
.
ForeignKey
(
RaceType
,
on_delete
=
models
.
CASCAD
E
)
participation_type
=
models
.
CharField
(
max_length
=
100
,
choices
=
RaceParticipationType
.
choices
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment