I have a Django app that will create a contract between two people. The user creates the contract and, upon creation, a random url-safe string is generated using secrets.
However, when I create more than one instance of a Contract, the slugs are the same. The only way to get a different randomly generated string is to restart my server. What am I doing wrong?
Here's the part that matters in my models.py
slug = models.SlugField(
default=secrets.token_urlsafe(64),
editable=False,
blank=False
)
Here are the last three Contracts I created. Changing the values of the other fields doesn't change the slug.
{
"model_email": "POOP@pooop.com",
"shoot_location": "Atlanta, GA",
"shoot_date": "2020-05-24",
"model_name": "",
"created_at": "2020-05-24T19:24:20.220845Z",
"sent_completed_to_model": null,
"sent_completed_to_photographer": null,
"photographer": 1,
"signed": false,
"slug": "Dqyk5-kDzE219_-abRKABETRuOCGOBxzvFVrXZaUGEe8ZLva6i6tdwUYMksSvKJ_BEABV_Vt1H_ttZ6p-yzRyg"
},
{
"model_email": "POOP@pooop.com",
"shoot_location": "Atlanta, GA",
"shoot_date": "2020-05-24",
"model_name": "",
"created_at": "2020-05-24T19:24:21.216218Z",
"sent_completed_to_model": null,
"sent_completed_to_photographer": null,
"photographer": 1,
"signed": false,
"slug": "Dqyk5-kDzE219_-abRKABETRuOCGOBxzvFVrXZaUGEe8ZLva6i6tdwUYMksSvKJ_BEABV_Vt1H_ttZ6p-yzRyg"
},
{
"model_email": "POOP@pooop.com",
"shoot_location": "Atlanta, GA",
"shoot_date": "2020-05-24",
"model_name": "",
"created_at": "2020-05-24T19:24:22.120845Z",
"sent_completed_to_model": null,
"sent_completed_to_photographer": null,
"photographer": 1,
"signed": false,
"slug": "Dqyk5-kDzE219_-abRKABETRuOCGOBxzvFVrXZaUGEe8ZLva6i6tdwUYMksSvKJ_BEABV_Vt1H_ttZ6p-yzRyg"
}