If it's a new object, you need to save it first and then access self.id, because
"There's no way to tell what the value of an ID will be before you call save(),
because that value is calculated by your database, not by Django."
Check django's document https://docs.djangoproject.com/en/dev/ref/models/instances/