Answer the question
In order to leave comments, you need to log in
Database query from Django template?
There is, in my opinion, a difficult task.
The site has a section with events (tasks), within which there are actions. Actions have a ForeignKey field with a status, there are only two statuses - "Completed" and "In Progress", statuses have Boolean fields - True and False, respectively.
Question: can I display the number of completed and not completed actions for each specific task, without creating fields in the database models?
I guess you can somehow refer to the model from the template, but I don’t know how, I haven’t found information on this subject either on the forums or in the official documentation, I’ll be glad if someone poke their nose.
models.py
# задача
class Merop(models.Model):
name = models.CharField('Название', max_length=250, null=False)
idProj = models.ForeignKey(Project, verbose_name='Проект', on_delete=models.SET_NULL, null=True)
idStatus = models.ForeignKey(StatusMerop, verbose_name='Статус мероприятия', on_delete=models.SET_NULL, null=True)
description = models.CharField('Примечание', max_length=2000, blank=True)
# действие в задаче
class Deist(models.Model):
name = models.CharField('Название', max_length=255, null=False)
idMerop = models.ForeignKey(Merop, verbose_name='Мероприятие', on_delete=models.CASCADE)
idStatus = models.ForeignKey(StatusDeist, verbose_name='Статус действия', on_delete=models.SET_NULL, null=True)
description = models.CharField('Примечание', max_length=2000, blank=True)
# статус действия
class StatusDeist(models.Model):
name = models.CharField('Статус', max_length=150, unique=True, null=False)
description = models.TextField('Примечание', max_length=2000, blank=True)
completed = models.BooleanField('Завершено', default=False, null=False)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question