I tried to have models.UUIDField
without dash, by using default=uuid.uuid4().hex
(Instead of default=uuid.uuid4()
)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
api_key = models.UUIDField(default=uuid.uuid4().hex, editable=False, unique=True)
subscription = models.IntegerField(
choices=[(s.value, s.name) for s in Subscription],
null=False,
blank=False
)
def __str__(self):
return str(self.api_key)
However, the resultant result still come with dash.
django=# select * from users_profile;
id | api_key | secret_key | subscription | user_id
----+--------------------------------------+------------+--------------+---------
1 | 9da3546c-660c-46c6-adc4-6a13e6ee202b | | 0 | 1
2 | 9cbc3a68-7f50-4b18-9e61-7b009f22a0e8 | | 0 | 2
(2 rows)
May I know how to have models.UUIDField field without dash?. I would like to store in database without dashes, and use it without dashes.