DarkShark
DarkShark

Reputation: 11

Should I use session for saving user data? Django

I'm new to django and I think sessions would be the best thing for my use case, but I'm not sure, maybe there are better possibilities?

This is my application simplified: Users should be able to select any number of train connections out of a database, and my application returns the best average mobile phone operator for their connections.

My models would be the following:

And to save the users (and thus their choosen connections) I would have used sessions, which save the user_id.

Is this possible and recommended?

Upvotes: 1

Views: 699

Answers (1)

codelessbugging
codelessbugging

Reputation: 2909

If you want the user's choices to persist longer than a single session, (i.e. I can come back to your app another time and be able to retrieve my choices), use a database to store it. You can look at https://tutorial.djangogirls.org/en/django_start_project/#set-up-a-database and https://tutorial.djangogirls.org/en/django_models/

Otherwise, if you do not want their choices to persist, then by all means use sessions.

Upvotes: 1

Related Questions