Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestions about django's user API (user id)
    primarykey
    data
    text
    <p>I'm looking at Django's built in implementation of users, and have a few questions</p> <ol> <li>What's the right way to identify users? Username are unique - so that could be an identifier, but they're easily changable (u.username = 'somethingelse', u.save()). Googling finds a <code>id</code> field, but why is that not in the docs (a mistake, or am I not supposed to use it?)</li> <li>How can I make the user id auto increment? Somewhere in the docs it recommends not deleting users, but I like letting users delete their info if they want to. I checked - and when deleting a user the user id is freed</li> <li>How does Django do concurrency? There are a couple threads on this about how to make your own queries concurrent-proof, but I didn't find anything on whether Django's built in classes (e.g. users) are concurrent. For example, is it possible that two users can register with the same username at the same time? That's a relatively simple example, as the table could be generated with a plain old constraint, but what about more complex cases (updating permissions?) that should(?) use transactions?</li> <li>Does django do "on delete cascade"? Back to question 2, if I delete a user, and everything related to that user id is deleted, off the top of my head I think it's okay if someone else gets the same id (might be confusing if someone bookmarks a page with the user id and now it's a new user)</li> </ol> <p>Example code of user being deleted and reusing the ID (in the django shell)</p> <pre><code>userA = User.objects.create_user('userA') userA.id # (prints 2 for example) # I go to the admin page, I see the new user userA.delete() # Admin page, userA gone userB = User.objects.create_user('userB') userB.id # (prints 2 again) # UserB is visible in the admin page </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload