Django Requests and Concurrency
I'm a little bit confused as to a few concepts regarding Django and concurrency. Suppose two users append data to the database or make a query at the same time. How do I determine what data to render for the user? I know each model has an id, but how is that associated with the user? Is this done mainly through the primary key field which you can add to Django views, or is this already done using Django sessions, and thus no need for management of primary keys or Django model ids? I've been researching for hours but I still don't understand this concept.
In Django, when multiple users make requests to the server at the same time, the requests are handled concurrently by the web server. Each request is handled in its own separate process or thread, and Django uses database transactions to ensure that the data accessed and modified by each request is isolated from the data accessed and modified by other requests.
When a user makes a request to the server, Django uses sessions to associate the request with a particular user. The session is typically stored in a cookie on the user's browser, and it contains a unique session ID that is sent back to the server with each request. Django uses this session ID to look up the user's session data and determine which user is making the request.
Django models have a primary key field, which is a unique identifier for each record in the database. This primary key is used to retrieve and update specific records in the database, and it is not necessarily related to the user.
In summary, Django uses sessions to associate requests with a particular user, and it uses database transactions to ensure that the data accessed and modified by each request is isolated from the data accessed and modified by other requests. And the primary key field of the model serves as a unique identifier for each record in the database and is not necessarily related to the user.
I hope this has solved your doubts