@geoom @Ire @lorenzo-peΓ±a Django, (is_medical, is_patient, is_physiotherapist) python
In [6]: User.objects.filter(username='agarcial').values('is_medical','is_patient','is_physiotherapist')
Out[6]: [{'is_physiotherapist': True, 'is_patient': True, 'is_medical': True}]
views.py , , (, )
class ProfileView(LoginRequiredMixin, TemplateView):
template_name = 'profile.html'
def get_context_data(self, **kwargs):
self.request.session['Hi'] = True
context = super(ProfileView, self).get_context_data(**kwargs)
is_auth = False
name = None
user = self.request.user
if user.is_medical:
print (user.is_medical)
is_auth = True
profile=user.get_medical_profile()
data = {
'is_auth':is_auth,
'profile':profile,
}
context.update({'userprofile':profile, 'data':data})
elif user.is_patient:
print (user.is_patient)
is_auth=True
profile=user.get_patient_profile()
data = {
'is_auth':is_auth,
'profile':profile,
}
context.update({'userprofile':profile,'data':data})
elif user.is_physiotherapist:
print (user.is_physiotherapist)
is_auth=True
profile=user.get_physiotherapist_profile()
data = {
'is_auth':is_auth,
'profile':profile,
}
context.update({'userprofile':profile,'data':data})
return context
def get_userprofile(self):
return self.request.user.userprofile
If I checked other possible combinations (patient-patient, medical and physiotherapist), can this work?
I think, create groups for (Medicals, Patients, Physiotherapists) and linking users for the authorization topic, although I should consider other things for the authorization process, such as django guardian for example?
How about this?
source
share