Hello!
I got a question how do I make tables using one of models field as headers, let me explain:
My models (please, don’t mind native language):
class Timeperiod(models.Model):
'''Периоды.'''
start_date = models.DateField('дата начала')
end_date = models.DateField('дата окончания')
target_duration = models.DurationField('длительность')
is_open = models.BooleanField('открыт', default=False)
class Meta:
verbose_name = 'период'
verbose_name_plural = 'периоды'
@property
def test(self) -> str:
return 'test'
@property
def days(self) -> list:
delta = self.end_date - self.start_date
ds = []
for i in range(delta.days + 1):
ds.append(self.start_date + timedelta(days=i))
return ds
def __str__(self) -> str:
return ' - '.join([str(self.start_date), str(self.end_date), str(self.target_duration), str(self.days)])
class Timetracking(models.Model):
'''Списания времени.'''
employee = models.ForeignKey(Employee, on_delete=models.PROTECT, verbose_name='сотрудник')
project = models.ForeignKey(Project, on_delete=models.PROTECT, verbose_name='проект')
timeperiod = models.ForeignKey(Timeperiod, on_delete=models.PROTECT, verbose_name='период')
date = models.DateField('дата')
time = models.DurationField('трудозатраты')
class Meta:
verbose_name = 'списание'
verbose_name_plural = 'списания'
def __str__(self) -> str:
return f'{self.employee} - {self.project}: {self.date} {self.time}'
I want to have data displayed like this:
Timeperiod.days[1] | … Timeperiod.days[n]
sum(all_timetrackings_at_that_day) | sum(all_timetrackings_at_that_day)
…
But I just have now idea where to start to get data like this