Sunday, January 28, 2018

Re: view user profile access restriction

Thanks heaps that worked. But then how to i retrieve the rest of the profile info from the second table? i have a one-to-one relationship. i mange to extract data from the user table which is first name, last name, email. but i am having difficulty figuring out accessing information from the second table (Profile)

view.py

ef loggin(request):
    username=None
    if request.user.is_authenticated:
        info=request.user
        return render(request,'dashboard.html',locals())




my model.py

class Profile(models.Model):
    user=models.OneToOneField(User, on_delete=models.CASCADE)
    bio=models.TextField(default='',blank=True)
    sex=(
            ('Male','Male'),
            ('Female','Female'),

    )

    Gender=models.CharField(max_length=100,choices=sex,blank=True,default='')
    Phone=models.CharField(max_length=20,blank=True,default='')
    island=models.CharField(max_length=100,blank=True,default='')
    city=models.CharField(max_length=100,blank=True,default='')
    country=models.CharField(max_length=100,blank=True,default='')
    organization=models.CharField(max_length=100,blank=True,default='')
   

    account_number=models.CharField(max_length=100,blank=True,default='')
    bank_phone=models.CharField(max_length=100,blank=True,default='')


def create_profile(sender, **kwargs):
    user = kwargs["instance"]
    if kwargs["created"]:
        user_profile = Profile(user=user)
        user_profile.save()
post_save.connect(create_profile, sender=User)








On Mon, Jan 29, 2018 at 1:02 PM, Dylan Reinhold <dreinhold@gmail.com> wrote:
There are a bunch of ways to do it.
Show us your view, if it's a function based view, just do your select on (username=request.user)

Dylan

On Sun, Jan 28, 2018 at 4:59 PM, sum abiut <suabiut@gmail.com> wrote:
Hi,
i have a django app that i want the users to be able to view only their user profile once they have login. currently any user that login is able to view other users profile as well. Appreciate is you could point me to the right direction.

cheers,

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y7ZZx0BfQe0jwZu8-h%2Bo7nU%3DZYg%3Dgr2nxYeU%2BjskVTCtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHtg44CnQo8DtMunvmR5StuFD3vw5y0dk8dJqXM46mtDuaxR_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y6QWOcy%3DH7%3DnBsTzSKFcChQM9uavenia%2BH2PokSd55gog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment