I am trying to extend a User model and add some fields and below is my approach:
Class UserProfile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
mobile_number = models.CharField(max_length=20)
gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
location = models.ForeignKey(Location, blank=True, null=True)
class User_One(UserProfile):
field_1 = models.CharField(max_length=20)
....
....
class User_Two(UserProfile):
field_1 = models.CharField(max_length=20)
....
....
So basically there are two types of users User_One
and User_Two
and now whenever we save the two types of users into database the following happens
- A
User
model record will be created with separate id of values 1,2,3 etc., - A
User_One
model record will be created with id's 1,2,3 - A
User_Two
model record will be created with id's 1,2,3
So for each every model record saving, Django or database was generating id's 1,2,3.
But I got a requirement that User model should generate a uuid
for id field value in place of integers, was that possible?
I mean something like below
class User_Profile(models.Model):
id = models.IntegerField(default=uuid.uuid4)