Yes, first you generate your custom key, second you specify it as the id of an object.
id = 'A1B2C3D4E5'
foo = Foo(id=id)
foo.save()
This code would create a record in the database. I also have to note that if you read this record to an object, changed it and saved it, the record wouldn't change, another record would be created with the new id
foo = Foo.objects.filter(id=id)[0]
foo.save()
Foo.objects.all()
<QuerySet [<Foo: Foo object (A1B2C3D4E5)>, <Foo: Foo object (X1Y2Z3)>]>
Olegсреда, 24 июня 2020 г. в 04:49:45 UTC+3, Clive Bruton: