X-Git-Url: https://code.kerkeslager.com/?p=climbing.kerkeslager.com;a=blobdiff_plain;f=src%2Fclimbing%2Fmodels.py;fp=src%2Fclimbing%2Fmodels.py;h=dd2493c4bdc66e5d4c5c6ebef1d120ff5dc966b1;hp=83d437f1e6b1c10f2dff565829c21028c50341ec;hb=4ea2032901c06985e8616e16e7d0bba6bb3c9a43;hpb=93c0a73c774d32afb5258ed584343aa49359741e diff --git a/src/climbing/models.py b/src/climbing/models.py index 83d437f..dd2493c 100644 --- a/src/climbing/models.py +++ b/src/climbing/models.py @@ -41,7 +41,34 @@ class Route(models.Model): notes = models.TextField(blank=True, null=True) def __str__(self): - return self.name + pitch_count = self.pitches.count() + + if pitch_count == 0: + return self.name + + if pitch_count == 1: + return '{} {}'.format(self.name, self.difficulty) + + return '{} {} ({} pitches)'.format( + self.name, + self.difficulty, + pitch_count, + ) + + @property + def difficulty(self): + diff = None + diff_index = -1 + + for pitch in self.pitches.all(): + for index, diff_choice in enumerate(ROUTE_DIFFICULTY_CHOICES): + if pitch.difficulty == diff_choice[0]: + if diff_index < index: + diff = pitch.difficulty + diff_index = index + break + + return diff ROUTE_DIFFICULTY_CHOICES = ( ('5.0', '5.0'), @@ -99,11 +126,14 @@ class Pitch(models.Model): on_delete=models.CASCADE, related_name='pitches', ) - name = models.CharField(max_length=64, null=True) + name = models.CharField(max_length=64, blank=True, null=True) difficulty = models.CharField(max_length=5, choices=ROUTE_DIFFICULTY_CHOICES) safety = models.CharField(max_length=4, choices=SAFETY_CHOICES) notes = models.TextField(blank=True, null=True) + class Meta: + verbose_name_plural = 'pitches' + def __str__(self): if self.name: return '{} ({})'.format(self.name, self.difficulty)