from django.contrib import admin
-# Register your models here.
+from . import models
+
+class PitchInline(admin.TabularInline):
+ model = models.Pitch
+
+class RouteAdmin(admin.ModelAdmin):
+ inlines = (
+ PitchInline,
+ )
+
+admin.site.register(models.Route, RouteAdmin)
+
+admin.site.register(models.Attempt)
+admin.site.register(models.Boulder)
+admin.site.register(models.BoulderDifficulty)
+admin.site.register(models.RouteDifficulty)
+admin.site.register(models.Todo)
-# Generated by Django 3.1.7 on 2021-02-25 19:26
+# Generated by Django 3.1.7 on 2021-02-25 19:46
from django.conf import settings
from django.db import migrations, models
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('notes', models.TextField()),
('protection', models.CharField(choices=[('none', 'None'), ('bolts', 'Bolts'), ('gear', 'Gear'), ('pad', 'Pad'), ('tr', 'Top Rope')], max_length=8)),
+ ('style', models.CharField(choices=[('onsight', 'On Sight'), ('flash', 'Flash'), ('project', 'Project'), ('other', 'Other')], max_length=8)),
('boulder', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='todos', to='tickle.boulder')),
('route', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='todos', to='tickle.route')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
name='Pitch',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('order', models.PositiveSmallIntegerField()),
('difficulty', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='pitches', to='tickle.routedifficulty')),
('route', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pitches', to='tickle.route')),
],
name='Attempt',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('date', models.DateField()),
('notes', models.TextField()),
('result', models.CharField(choices=[('send', 'Sent'), ('fall', 'Fall')], max_length=8)),
('prior_knowledge', models.BooleanField(default=True)),
--- /dev/null
+# Generated by Django 3.1.7 on 2021-02-25 19:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('tickle', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='boulder',
+ name='mountainproject',
+ field=models.URLField(blank=True, default=''),
+ preserve_default=False,
+ ),
+ migrations.AlterField(
+ model_name='route',
+ name='mountainproject',
+ field=models.URLField(blank=True, default=''),
+ preserve_default=False,
+ ),
+ ]
on_delete=models.PROTECT,
related_name='boulders',
)
- mountainproject = models.URLField(null=True)
+ mountainproject = models.URLField(blank=True)
+
+ def __str__(self):
+ return '{} ({})'.format(self.name, self.difficulty)
class BoulderDifficulty(models.Model):
order = models.PositiveSmallIntegerField()
name = models.CharField(max_length=8)
+ class Meta:
+ ordering = ('order',)
+
+ def __str__(self):
+ return self.name
+
class Pitch(models.Model):
+ order = models.PositiveSmallIntegerField()
route = models.ForeignKey(
'Route',
on_delete=models.CASCADE,
related_name='pitches',
)
+ class Meta:
+ ordering = ('order',)
+
+ def __str__(self):
+ return 'P{} ({})'.format(self.order, self.difficulty)
+
PROTECTION_STYLE_CHOICES = (
('sport', 'Sport'),
('toprope', 'Top Rope'),
class Route(models.Model):
name = models.CharField(max_length=64)
protection_style = models.CharField(max_length=8, choices=PROTECTION_STYLE_CHOICES)
- mountainproject = models.URLField(null=True)
+ mountainproject = models.URLField(blank=True)
# TODO Write test for this
@property
def difficulty(self):
return self.pitches.order_by('-difficulty__order').first().difficulty
+ def __str__(self):
+ return '{} ({})'.format(self.name, self.difficulty)
+
class RouteDifficulty(models.Model):
order = models.PositiveSmallIntegerField()
name = models.CharField(max_length=8)
+ def __str__(self):
+ return self.name
+
ATTEMPT_RESULT_CHOICES = (
('send', 'Sent'),
('fall', 'Fall'),
class Attempt(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
+ date = models.DateField()
notes = models.TextField()
boulder = models.ForeignKey('Boulder', null=True, on_delete=models.PROTECT, related_name='attempts')
route = models.ForeignKey('Route', null=True, on_delete=models.PROTECT, related_name='attempts')
),
)
+ ordering = ('date',)
+
STYLE_CHOICES = (
('onsight', 'On Sight'),
('flash', 'Flash'),
- ('complete', 'Complete'),
- ('project', 'project'),
+ ('project', 'Project'),
+ ('other', 'Other'),
)
class Todo(models.Model):
protection = models.CharField(max_length=8, choices=PROTECTION_CHOICES)
boulder = models.ForeignKey('Boulder', null=True, on_delete=models.PROTECT, related_name='todos')
route = models.ForeignKey('Route', null=True, on_delete=models.PROTECT, related_name='todos')
+ style = models.CharField(max_length=8, choices=STYLE_CHOICES)
class Meta:
constraints = (
name='todo_boulder_xor_route',
),
)
+
+ ordering = ('route__name',)
+
+ def __str__(self):
+ if self.boulder:
+ climb = self.boulder
+ elif self.route:
+ climb = self.route
+ else:
+ raise Exception()
+
+ return '{} {}'.format(self.style, climb)