N
N
NyxDeveloper2021-01-14 12:49:13
Django
NyxDeveloper, 2021-01-14 12:49:13

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

1 answer(s)
D
Dr. Bacon, 2021-01-14
@NyxDeveloper

annotate - https://docs.djangoproject.com/en/3.1/ref/models/q...
all features https://docs.djangoproject.com/en/3.1/topics/db/ag...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question