0
class AssignedTask(Task):
deadline = models.DateField()
amount = models.IntegerField(blank=True)
priority = models.FloatField()

def priority_set(self):
    delta = self.deadline - timezone.now().date()
    self.priority = delta.days / self.importance
    self.save()

def __str__(self):
    return self.title

I want to set a value of the 'priority' field when data AssignedTask is created, but the priority field always returns null when I create data with a mutation in graphQL API.

1
  • Are you sure you need this as a field? It would be better to keep it as a method, so you can call it when you need to display the value. Sep 22, 2019 at 8:25

1 Answer 1

0

Overwrite the save method

def save(self):
    self.priority_set()
    super().save()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.