What I'm trying to do is whenever the user requests an API key--regardless of whether the user already generated one or not--the system will generate an entirely new key.
I know that whenever calling ApiKey.objects.create()
will generate an API key for the user that doesn't have one generated. However, if a user does have one, then trying to call the .create()
method throws an error.
In this case, I figured that it would be best to write my own key generator. However, I am now hoping that maybe someone here might know of a helper function that will allow me to generate a random API key, and then let me save it to the database manually myself.
Would anyone might know of any such a helper function?
api_key.key = None; api_key.save()
out of the try block, possible into an else block, to be as precise as possible about what you're trying. – Jacks