class School(models.Model): class Meta: verbose_name = 'škola' verbose_name_plural = 'školy' code = models.AutoField(verbose_name='kód', primary_key=True) name = models.CharField(verbose_name='názov', max_length=100) abbreviation = models.CharField(verbose_name='skratka', max_length=10) street = models.CharField(verbose_name='ulica', max_length=100) city = models.CharField(verbose_name='obec', max_length=100) zip_code = models.CharField(verbose_name='PSČ', max_length=6) email = models.CharField(verbose_name='email', max_length=50, blank=True) district = models.ForeignKey(District, verbose_name='okres', on_delete=models.SET( District.objects.get_unspecified_value)) objects = UnspecifiedValueManager(unspecified_value_pk=0) @property def printable_zip_code(self): return self.zip_code[:3] + ' ' + self.zip_code[3:] def __str__(self): if self.street and self.city: return f'{ self.name }, { self.street }, { self.city }' return self.name @property def stitok(self): return f'\\stitok{{{ self.name }}}{{{ self.city }}}' \ f'{{{ self.printable_zip_code }}}{{{ self.street }}}'
class Grade(models.Model): class Meta: verbose_name = 'ročník účastníka' verbose_name_plural = 'ročníky účastníka' ordering = [ 'years_until_graduation', ] name = models.CharField(verbose_name='názov ročníku', max_length=32) tag = models.CharField(verbose_name='skratka', max_length=2, unique=True) years_until_graduation = models.SmallIntegerField( verbose_name='počet rokov do maturity') is_active = models.BooleanField(verbose_name='aktuálne používaný ročník') objects = UnspecifiedValueManager(unspecified_value_pk=13) def get_year_of_graduation_by_date(self, date=None): return utils.get_school_year_end_by_date( date) + self.years_until_graduation @staticmethod def get_grade_by_year_of_graduation(year_of_graduation, date=None): years_until_graduation = year_of_graduation - \ utils.get_school_year_end_by_date(date) try: grade = Grade.objects.get( years_until_graduation=years_until_graduation) except Grade.DoesNotExist: grade = Grade.objects.get_unspecified_value() return grade def __str__(self): return self.name
class School(models.Model): class Meta: verbose_name = 'škola' verbose_name_plural = 'školy' code = models.AutoField(primary_key=True, verbose_name='kód') name = models.CharField(max_length=100, verbose_name='názov') abbreviation = models.CharField(max_length=10, verbose_name='skratka') street = models.CharField(max_length=100, verbose_name='ulica') city = models.CharField(max_length=100, verbose_name='obec') zip_code = models.CharField(max_length=6, verbose_name='PSČ') email = models.CharField(max_length=50, verbose_name='email', null=True) district = models.ForeignKey(District, on_delete=models.SET( District.objects.get_unspecified_value), verbose_name='okres') objects = UnspecifiedValueManager(unspecified_value_pk=0) def __str__(self): if self.street and self.city: return f'{ self.name }, { self.street }, { self.city }' return self.name @property def stitok(self): return f'\\stitok{{{ self.name }}}{{{ self.city }}}' \ f'{{{ self.zip_code }}}{{{ self.street }}}'
class County(models.Model): class Meta: verbose_name = 'kraj' verbose_name_plural = 'kraje' code = models.AutoField(verbose_name='kód', primary_key=True) name = models.CharField(verbose_name='názov', max_length=30) objects = UnspecifiedValueManager(unspecified_value_pk=0) def __str__(self): return self.name
class District(models.Model): class Meta: verbose_name = 'okres' verbose_name_plural = 'okresy' code = models.AutoField(verbose_name='kód', primary_key=True) name = models.CharField(verbose_name='názov', max_length=30) abbreviation = models.CharField(verbose_name='skratka', max_length=2) county = models.ForeignKey( County, verbose_name='kraj', on_delete=models.SET(County.objects.get_unspecified_value)) objects = UnspecifiedValueManager(unspecified_value_pk=0) def __str__(self): return self.name