'Django model instance default value

I have Django model

  name        = models.CharField(max_length=255)
  excerpt     = models.TextField()
  desc        = models.TextField()
  due_date    = models.DateTimeField()
  created_at  = models.DateTimeField()
  priority    = models.IntegerField(default = 1)

When I create model instance, I want to set priority value to maximum value among all instances incremented by one. (max(priority)+1). Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source