I used to set the default value of an integer field like this. But with migrations it's not working anymore. What's the proper way to do it?
class Rechnung(models.Model):
nummer = models.IntegerField(default=lambda: Rechnung.objects.latest('id').nummer + 1)
[...]
You can grab this value in the model save method. Save runs for both create and update, so check it's a new object, then set the default if it's new:
Another way is to replace lambda with a custom function:
Note that you provide the callable as a default, so django calls it each time the default is required (like lambda in the previous version)