Lets say we have the following model:
class MyModel(models.Model):
some_int = models.IntegerField()
I would like the value of MyModel.some_int
to default to the value of MyModel.id
.
For example, immediately after creating a new record in an empty version of MyModel, I could call MyModel.objects.get(id=1)
and receive an object with id=1 and some_int=1. Is there a way to do this?
Edit: My current workaround is to set the default to 0, then go back and populate the value with the id
of the created record, but that is messy.
For context: On an existing model similar to MyModel
, I am being asked to add a new column that will render using the MyModel
index obsolete as the reference point for the records in that model. Instead, I am adding a new, secondary column, that should store the values of the old IDs for previous records, and new values for future records. To do that though, I need to populate the column first.