I manage to fixed it. I have created two instances (profile_info and info) in my view, i use the first instance to access the information from my Profile model and the second instance to access th User model. I also set the AUTH_PROFILE_MODULE = 'Profile' in my settings.py.
my updated view.py
def loggin(request):
if request.user.is_authenticated:
profile_info=request.user.profile
info=request.user
return render(request,'dashboard.html',locals())
if request.user.is_authenticated:
profile_info=request.user.profile
info=request.user
return render(request,'dashboard.html',locals())
cheers,
On Mon, Jan 29, 2018 at 3:17 PM, sum abiut <suabiut@gmail.com> wrote:
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:DylanThere 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)--On Sun, Jan 28, 2018 at 4:59 PM, sum abiut <suabiut@gmail.com> wrote:--cheers,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.
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-y7ZZx0B .fQe0jwZu8-h%2Bo7nU%3DZYg%3Dgr2 nxYeU%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/CAHtg44CnQo8D .tMunvmR5StuFD3vw5y0dk8dJqXM46m tDuaxR_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-y5PMBn70mJf72da-NPJPs2Kgf%2B%2BUArMP1orLqdXOYaotQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment