Hello All!

I need your help. I have a table, PersonWife, that's linked in a one-to-one 
fashion with the users (using Django's  user authentication system). See 
attached models and admin control panel screenshots.

I can get the username of the currently logged in user ( attached 
screenshots). What I'm trying to do is that having the username of the 
currently logged in user, I now want to access with whom the user is linked 
to that one-to-one table and have the name of that person (wife's name).
For example, in my test the user's username is test_user1 and the name of 
the wife is Carol. How to I get Carol to find Carol in the code?
This is my script so far:

from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from . models import PersonWife

def home(request):
    context = {}
    return render(request, 'myapp/index.html', context)


@login_required
def get_wife_name(request):
    #  Check if user is authenticated to get his id
    if request.user.is_authenticated:
        user_username = request.user
        username = user_username.username
        print(username)
        context = {'username':username}
    return render(request, 'myapp/relationship.html', context)

Thanks

-- 
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/9a0e67ee-d27b-468c-9879-22d2890ff234n%40googlegroups.com.

Reply via email to