DB structure reworked little bit more

This commit is contained in:
2022-07-14 16:21:56 +03:00
parent 2c928e7952
commit 35398809ce
4 changed files with 15 additions and 34 deletions
-2
View File
@@ -1,12 +1,10 @@
from django.contrib import admin
from .models import YearData
from .models import MonthData
from .models import DayData
from .models import Event
from .models import CalendarData
admin.site.register(YearData)
admin.site.register(MonthData)
admin.site.register(DayData)
admin.site.register(Event)
admin.site.register(CalendarData)
+14 -30
View File
@@ -39,41 +39,25 @@ class MonthData(models.Model):
return f'({self.number}, {self.name}, {self.folkname}, {self.is_oneday}, {self.is_leap_month})'
class DayData(models.Model):
number = models.SmallIntegerField('Number', unique=True, validators=[
class CalendarData(models.Model):
current_day = models.SmallIntegerField('Number', unique=True, validators=[
MinValueValidator(1),
MaxValueValidator(30),
])
current_month = models.ForeignKey(MonthData, on_delete=models.CASCADE)
current_year = models.ForeignKey(YearData, on_delete=models.CASCADE)
def __str__(self):
return f'({self.current_day}, {self.current_month}, {self.current_year})'
class Event(models.Model):
day = models.SmallIntegerField('Number', unique=True, validators=[
MinValueValidator(1),
MaxValueValidator(30),
])
month = models.ForeignKey(MonthData, on_delete=models.CASCADE)
year = models.ForeignKey(YearData, on_delete=models.CASCADE)
def __str__(self):
return f'({self.number, self.month})'
class CalendarData(models.Model):
current_day = models.ForeignKey(DayData, on_delete=models.CASCADE)
def __str__(self):
return f'({self.current_day})'
@property
def current_month(self):
try:
return getattr(self.current_day, 'month')
except AttributeError:
return None
@property
def current_year(self):
try:
return getattr(self.current_day, 'year')
except AttributeError:
return None
class Event(models.Model):
day = models.ForeignKey(DayData, on_delete=models.CASCADE)
time = models.TimeField('Time')
title = models.CharField('Title', max_length=250)
description = models.TextField('Description', max_length=2500)
@@ -13,7 +13,7 @@
<tr>
{% endif %}
{% if day == calendar_data.current_day.number and year_data == calendar_data.current_year and month == calendar_data.current_month %}
{% if day == calendar_data.current_day and year_data == calendar_data.current_year and month == calendar_data.current_month %}
<td class="current">
{% else %}
<td>
-1
View File
@@ -4,7 +4,6 @@ from django.http import HttpResponseNotFound
from .models import YearData
from .models import MonthData
from .models import DayData
from .models import CalendarData
from .models import Event