Sunday, July 5, 2020

Re: how to give permission to a logged in specific user in a list of users profile


On Mon, 6 Jul 2020 at 03:13, Arpana Mehta <arpana11mehta@gmail.com> wrote:
You can user permission classes in your code. Or decorators before the function view you want to be only visible to logged in users.

from django.contrib.auth.decorators import login_required      @login_required
def your_view_here(request):


On Mon, 6 Jul 2020 at 01:28, Exactly musty <exactmusty1994@gmail.com> wrote:
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+unsubscribe@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.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGyqUuX8-1r7ec8XRADGQAdhTYeFN2WUyo%2BY2Fb-s5daq3t4YA%40mail.gmail.com.

No comments:

Post a Comment