I also, I have build one program with health environment, and the user
controlls is following manner:

def login_ini(request):
variable1 = 'Pantalla de Acceso al Sistema'
error_log = 'ok'
username = request.POST.get('username')
password = request.POST.get('password') # valor del template
user = auth.authenticate(username=username, password=password)
if request.method == "POST":
if user is not None and user.is_active:
# Correct password, and the user is marked "active"
auth.login(request, user)
request.session['username_x'] = username # variable gobal
request.session['id_x'] = user.id # variable gobal
#return HttpResponse(str(user.id))
return HttpResponseRedirect("principal")

error_log = "error"

context ={"variable1":variable1,"error_log":error_log,}
return render(request,"login_ini.html",context)
context ={
'user':user,
"variable1":variable1,
"error_log":error_log,
}
return render(request,'login_ini.html',context)


def log_out(request):
id_x = request.session.get('id_x')
log_out_x  = datetime.now()
cursor = connection.cursor()
cursor.execute(
"update auth_user set log_out=%s where id=%s",[log_out_x,id_x]  #
)
logout(request)
return redirect('login_ini')

and in template:
   {% if perms.ai.btn_acep_fichacui %}
<button type="submit" id="submit" name = "submit" class="btn
btn-primary">Aceptar</button>
{%else%}
<a style="font-size:14px" role="button" class="btn btn-primary"
onclick="alert('Usted no esta autorizado a grabar cambios a la
ficha')">Aceptar</a>
{%endif%}

if you have some question, contact me to: gabrielaraya2...@gmail.com


Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos
99.7721.15.70



El dom., 5 jul. 2020 a las 15:57, Exactly musty (<exactmusty1...@gmail.com>)
escribió:

> how can i specify a user in django templates, for example i have a page
> which consist of list of users available but i want it to show "Talk to a
> patient" for only the logged in user on his own profile here is what am
> saying in picture and here is my code, i actually don't know how to put the
> code i have tried many code but it does show Talk to a patient for every
> users or it wont show at all,i attached a picture to it,that shows what am
> saying,i checked the doc but couldn't find anything to use,so i wanted to
> try the custom templates tags,but i still don't how to comport the code in
> the templatetags views
>
> *Models.py*
>
>
>
> class Doctor(models.Model):
>     GENDER_CHOICES = (
>         ('Male', 'Male'),
>         ('Female', 'Female'),
>     )
>     user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, null=
> True, related_name="doctor")
>     image = models.ImageField(default='jazeera.jpg', upload_to='
> profile_pics')
>     full_name = models.CharField(max_length=100)
>     bio = models.TextField()
>     speciality = models.CharField(max_length=300)
>     describtion = models.CharField(max_length=100)
>     status = models.ManyToManyField(Status)
>     gender = models.CharField(max_length=6, choices=GENDER_CHOICES)
>     location = models.CharField(max_length=100)
>     certification = models.CharField(max_length=300)
>     place_of_work = models.CharField(max_length=300)
>
>
>
>
>
> *##template*
> {% if request.user == doctor %}
>                     <p><a href="{% url 'chat' %}" class="btn btn-primary
> ">Talk to a Patient</a></p>
>                       {% endif %}
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4278d2eb-53a1-4b9c-89fa-a5d09f96c458o%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4278d2eb-53a1-4b9c-89fa-a5d09f96c458o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKVvSDC2K-zPX8NE73SxS-5FeQs5pce5%3DqJ5Y-8Qy0bEHq%3DU2g%40mail.gmail.com.

Reply via email to