--- /dev/null
+# Generated by Django 4.0.3 on 2022-03-13 17:16
+
+from django.db import migrations, models
+
+SAFETY_CHOICES = (
+ ('G', 'G'),
+ ('PG', 'PG'),
+ ('PG13', 'PG13'),
+ ('R', 'R'),
+ ('X', 'X'),
+)
+
+BOULDER_DIFFICULTY_CHOICES = (
+ ('V0', 'V0'),
+ ('V1', 'V1'),
+ ('V2', 'V2'),
+ ('V3', 'V3'),
+ ('V4', 'V4'),
+ ('V5', 'V5'),
+ ('V6', 'V6'),
+ ('V7', 'V7'),
+ ('V8', 'V8'),
+ ('V9', 'V9'),
+ ('V10', 'V10'),
+ ('V11', 'V11'),
+ ('V12', 'V12'),
+ ('V13', 'V13'),
+ ('V14', 'V14'),
+ ('V15', 'V15'),
+ ('V16', 'V16'),
+ ('V17', 'V17'),
+)
+
+def forward(app, schema_editor):
+ Pitch = app.get_model('climbing', 'Pitch')
+ Problem = app.get_model('climbing', 'Problem')
+
+ safety_choices = {
+ s[0]: i
+ for i, s in enumerate(SAFETY_CHOICES)
+ }
+
+ difficulty_choices = {
+ d[0]: i
+ for i, d in enumerate(BOULDER_DIFFICULTY_CHOICES)
+ }
+
+ for p in Pitch.objects.all():
+ p.safety = safety_choices[p.safety_old]
+ p.save()
+
+ for p in Problem.objects.all():
+ p.difficulty = difficulty_choices[p.difficulty_old]
+ p.safety = safety[p.safety_old]
+ p.save()
+
+def backward(app, schema_editor):
+ Pitch = app.get_model('climbing', 'Pitch')
+ Problem = app.get_model('climbing', 'Problem')
+
+ for p in Pitch.objects.all():
+ p.safety_old = SAFETY_CHOICES[p.safety][0]
+ p.save()
+
+ for p in Problem.objects.all():
+ p.difficulty_old = BOULDER_DIFFICULTY_CHOICES[p.difficulty][0]
+ p.safety_old = SAFETY_CHOICES[p.safety][0]
+ p.save()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('climbing', '0009_rename_safety_pitch_safety_old_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='pitch',
+ name='safety',
+ field=models.IntegerField(choices=[(0, 'G'), (1, 'PG'), (2, 'PG13'), (3, 'R'), (4, 'X')], default=0),
+ preserve_default=False,
+ ),
+ migrations.AddField(
+ model_name='problem',
+ name='difficulty',
+ field=models.IntegerField(choices=[(0, 'V0'), (1, 'V1'), (2, 'V2'), (3, 'V3'), (4, 'V4'), (5, 'V5'), (6, 'V6'), (7, 'V7'), (8, 'V8'), (9, 'V9'), (10, 'V10'), (11, 'V11'), (12, 'V12'), (13, 'V13'), (14, 'V14'), (15, 'V15'), (16, 'V16'), (17, 'V17')], default=0),
+ preserve_default=False,
+ ),
+ migrations.AddField(
+ model_name='problem',
+ name='safety',
+ field=models.IntegerField(choices=[(0, 'G'), (1, 'PG'), (2, 'PG13'), (3, 'R'), (4, 'X')], default=0),
+ preserve_default=False,
+ ),
+ migrations.RunPython(forward, backward),
+ ]
YDS_5_15c = 37, '5.15c'
YDS_5_15d = 38, '5.15d'
-SAFETY_CHOICES = (
- ('G', 'G'),
- ('PG', 'PG'),
- ('PG13', 'PG13'),
- ('R', 'R'),
- ('X', 'X'),
-)
+class Safety(models.IntegerChoices):
+ G = 0, 'G'
+ PG = 1, 'PG'
+ PG13 = 2, 'PG13'
+ R = 3, 'R'
+ X = 4, 'X'
class Pitch(models.Model):
route = models.ForeignKey(
)
name = models.CharField(max_length=64, blank=True, null=True)
difficulty = models.PositiveIntegerField(choices=RouteDifficulty.choices)
- safety = models.CharField(max_length=4, choices=SAFETY_CHOICES)
+ safety = models.IntegerField(choices=Safety.choices)
notes = models.TextField(blank=True, null=True)
class Meta:
def __str__(self):
return self.name
-BOULDER_DIFFICULTY_CHOICES = (
- ('V0', 'V0'),
- ('V1', 'V1'),
- ('V2', 'V2'),
- ('V3', 'V3'),
- ('V4', 'V4'),
- ('V5', 'V5'),
- ('V6', 'V6'),
- ('V7', 'V7'),
- ('V8', 'V8'),
- ('V9', 'V9'),
- ('V10', 'V10'),
- ('V11', 'V11'),
- ('V12', 'V12'),
- ('V13', 'V13'),
- ('V14', 'V14'),
- ('V15', 'V15'),
- ('V16', 'V16'),
- ('V17', 'V17'),
-)
+class BoulderDifficylty(models.IntegerChoices):
+ V0 = 0, 'V0'
+ V1 = 1, 'V1'
+ V2 = 2, 'V2'
+ V3 = 3, 'V3'
+ V4 = 4, 'V4'
+ V5 = 5, 'V5'
+ V6 = 6, 'V6'
+ V7 = 7, 'V7'
+ V8 = 8, 'V8'
+ V9 = 9, 'V9'
+ V10 = 10, 'V10'
+ V11 = 11, 'V11'
+ V12 = 12, 'V12'
+ V13 = 13, 'V13'
+ V14 = 14, 'V14'
+ V15 = 15, 'V15'
+ V16 = 16, 'V16'
+ V17 = 17, 'V17'
+
class Problem(models.Model):
boulder = models.ForeignKey(
related_name='problems',
)
name = models.CharField(max_length=64)
- difficulty = models.CharField(max_length=3, choices=BOULDER_DIFFICULTY_CHOICES)
- safety = models.CharField(max_length=4, choices=SAFETY_CHOICES)
+ difficulty = models.IntegerField(choices=BoulderDifficylty.choices)
+ safety = models.IntegerField(choices=Safety.choices)
mountain_project = models.URLField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)