From this answer, the easiest way is to override the get_changeform_initial_data function.
This is how I applied it to my project.
In this example, I have an ORM class named Step and an Admin class named StepAdmin . The get_latest_step_order function gets the step_order from the last object in the table.
By overriding the get_changeform_initial_data strong> function in the admin class, I can set the step order for each new object created on the admin screen.
class Step(models.Model): step_name = models.CharField(max_length=200) step_status = models.ForeignKey(StepStatus, null=True) step_order = models.IntegerField() def get_latest_step_order(): return Step.objects.latest('step_order').step_order+1 class StepAdmin(admin.ModelAdmin): fields = ["step_name","step_status","step_order"] def get_changeform_initial_data(self, request): return { 'step_order': get_latest_step_order() }
source share