I am developing a dashboard app where all the objectives, results, etc have one dashboard as the FK. Right now it’s just 1 dashboard, but I want a user to be able to select a dashboard from a list and the selected dashboard’s id be saved so I can filter all the related objects when displaying them.
For example, after logging in the user would be directed to a drop down style list to select the dashboard to display/update; and the dashboard id would be used in each view unit the user logs out. User.id won’t work because a user could have a number of dashboards associated with the id.
Are there any good examples or documentation to help me figure this out?
n=1 # Dashboard id number returned from button_id in GET data - will be set in final using request.GET()
request.session['dashboard_id'] = n #assign dashboard_id the value n
will assign the value selected from the list in the session, and I should do that in the first view called after selecting the dashboard.
I can retrieve the active dashboard with:
dashboard_id = request.session.get('dashboard_id') # This how you retrieve the id in any view
and use that to filter results with dashboard.id = dashboard_id or simply use:
If you’re using the database session store, the session data is stored in the session as a JSON data object within the session_data field. This allows Django to store all the data for a session in one row of the database.
Personally I think storing it in the session is almost always the wrong thing to do. It means your app forgets what the user was doing after each login, and between devices. I always find that frustrating when apps do that. I would add a field on your custom user/profile model for it.