2017-10-17 97 views
0

我有代码,就像是人在登录以下内容:是怎么开始从用户的配置文件在Django

if request.method == 'POST': 

username = request.POST.get('username') 
password = request.POST.get('password') 

user = authenticate(username=username, password=password) 

if user: 
    # Check it the account is active 
    if user.is_active: 

     # Log the user in. 
     login(request, user) 

我已经扩展了用户创建一个用户配置。它包含其他信息。例如:地址,城市,州等

如何从这种情况下提取用户配置文件?对于Eclipse下的Java,如果我输入“user”,则会看到将应用于对象“user”的所有有效方法。

PyCharm没有出现这种功能。

就这么说,如何找到与用户相关的配置文件信息呢?

TIA

下面是简介型号代码:

class UserProfileInfo (models.Model): 
    class Meta: 

     db_table = 'mstrauthdjprofile' 
     db_tablespace = 'PSAPUSR1001' 

    user = models.OneToOneField(User) 

    restrole = models.BigIntegerField(blank=True, null=True, default=0) 

    profilepic = models.ImageField(upload_to='profile_pics', blank=True) 

    lastpgprocno = models.BigIntegerField(blank=True, null=True, default=-1) 
    currentpgprocno = models.BigIntegerField(blank=True, null=True, default=-1) 
    nextpgprocno = models.BigIntegerField(blank=True, null=True, default=1) 

    reclocktype = models.BigIntegerField(blank=True, null=True, default=0) 
    reclockid = models.BigIntegerField(blank=True, null=True, default=0) 

    def __str__(self): 
     return self.user.username 
+0

添加您的个人资料模型代码 –

+0

@NeErAj库马尔 - 已将其添加到消息中。有任何想法吗? –

+1

尝试'user.userprofileinfo'获取配置文件对象,第一个'user'应该是django的默认用户实例 –

回答

1

OneToOneField s为总是从自己的同行进行访问。

user = authenticate(username=username, password=password) 
user.userprofileinfo 

user = User.objects.first() 
user.userprofileinfo 

user_profile_info = UserProfileInfo.objects.first() 
user_profile_info.user 

你可以在你的代码中插入一个断点(我相信PyCharm应该有一个自动化的方式来处理这个问题)使用像PDB调试器:

import pdb; pdb.set_trace() 

,这将使你与互动当前范围。您可以查看哪些属性一个对象具有__dict__

user.__dict__ 
{'username': 'user', 'id': 1, ...} 

也可以考虑更强大的/交互式调试器像IPython的或bpython,具有自动完成内置的。

相关问题