I'd like to develop an app for multiple clients that displays analytics data specific to their account. So far I've set up my views file using the @login_required
decorator for restricted pages. Now I need to identify that user to obtain their data.
A bit of research suggests that I could use:
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User
session_key = request.session.session_key()
session = Session.objects.get(session_key=session_key)
uid = session.get_decoded().get('_auth_user_id')
Which obviously returns the user_id, which I can use as a field in the analytics database to identify which user the data belongs to.
Is this the best way to go about doing this, or can anyone suggest a better/more elegant alternative?
Note: I haven't tested the solution I've proposed, it just seems workable in my head.