I am aware of similar questions such as this or this but I could not get to work none of the answers.
I have two models in one models.py file:
class Vehicle(models.Model):
token = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=50)
class Model(models.Model)
token = models.OneToOneField(Users, on_delete=models.CASCADE, primary_key=True)
color = models.CharField(max_length=10, blank=True)
I want to upon adding a new Vehicle in django admin panel, a new record of Model also gets created and automatically bind the two on the same token which is in newly created Vehicle.
I know that I should set the default
value of OneToOneField
in Model class but I do not know how to get the token
of newly created Vehicle.