N
N
NikClik2018-07-03 17:38:37
Django
NikClik, 2018-07-03 17:38:37

The ban on editing the field, the calculation of this field, how?

I have 2 models, tasks are written in the first, subtasks of this task are written in the second.

class GroupTasks(models.Model):
    TASK_STATUS = {
        ('В процессе выполенеия', 'В процессе выполенеия'),
        ('В ожидании выполнения', 'В ожидании выполнения'),
        ('Выполнение закончено', 'Выполнение закончено'),
    }
    owner = models.CharField(blank=True, verbose_name="Владелец", max_length=1000000)
    header = models.CharField(blank=False, verbose_name="Заголовок задачи", max_length=1000000)
    dateOfStart = models.DateTimeField(blank=False, verbose_name="Дата, время начала задачи")
    dateOfEnd = models.DateTimeField(blank=True, verbose_name="Дата, время окончания задачи")
    progress = models.IntegerField(default=0, verbose_name="Прогресс")
    status = models.CharField(choices=TASK_STATUS, verbose_name="Статус", max_length=1000000, default="В ожидании выполнения")

    def __str__(self):
        return "Групповые задачи %s %s %s %s" % (self.pk, self.dateOfStart, self.dateOfEnd, self.progress)

    class Meta:
        verbose_name = 'Групповые задачи'
        verbose_name_plural = 'Групповые задачи'

<b>class UnderTask(models.Model):</b>
    TASK_STATUS = {
        ('В процессе выполенеия', 'В процессе выполенеия'),
        ('В ожидании выполнения', 'В ожидании выполнения'),
        ('Выполнение закончено', 'Выполнение закончено'),
    }
    headerTask = models.ForeignKey(GroupTasks, on_delete=models.CASCADE)
    creator = models.CharField(max_length=1000000, verbose_name="Создатель", blank=True)
    excerpt = models.CharField(max_length=1000000, verbose_name="Выполняющий")
    actions = models.TextField(blank=False, max_length=1000000, verbose_name="Выполняемые работы")
    dateOfStart = models.DateTimeField(blank=False, verbose_name="Дата, время начала задачи")
    dateOfEnd = models.DateTimeField(blank=True, verbose_name="Дата, время окончания задачи")
    step = models.IntegerField(blank=False, default=0)
    status = models.CharField(choices=TASK_STATUS, default="В ожидании выполнения", max_length=1000000, verbose_name="Статус выполнения")

    class Meta:
        verbose_name = 'Подзадачи'
        verbose_name_plural = 'Подзадачи'

Firstly, I need to make sure that no one can edit the progress field in GroupTasks, how can I do this?
Secondly, as you can see, UnderTask has a step field that is responsible for the step in the task (i.e. if step = 5, then 5% of 100% of the task (progress) is completed), how can I make it so that when the status UnderTask changes to "Execution completed" add GroupTasks.progress and UnderTask.step?
I understand that this can be done somehow by overriding some methods in admin, but I don’t know which ones, tell me which ones please

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question