-
-
Save nck2/ac7d813751f6869cb181271ef767c5da to your computer and use it in GitHub Desktop.
외래키 접근 방법 질문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
class Profile(models.Model): | |
user = models.OneToOneField(settings.AUTH_USER_MODEL) | |
phone_number = models.CharField(max_length=20, verbose_name="전화번호") | |
address = models.CharField(max_length=30, verbose_name="분반") | |
# views.py | |
@login_required | |
def profile(request,userid): | |
User=get_user_model() | |
me= User.objects.get(id=userid) | |
mypro = Profile.objects.filter(user=me) | |
print('mypro',mypro) # 출력결과: mypro <QuerySet []> | |
print('me',me) # 출력결과: me testuser | |
return render(request, 'accounts/profile.html',{'mypro':mypro,}) | |
#urls.py | |
url(r'^profile/(?P<userid>[0-9]+)/$', views.profile, name='profile') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment