Check if OneToOneField is None in Django

后端 未结 8 1638
走了就别回头了
走了就别回头了 2021-01-30 10:04

I have two models like this:

class Type1Profile(models.Model):
    user = models.OneToOneField(User, unique=True)
    ...


class Type2Profile(models.Model):
            


        
8条回答
  •  有刺的猬
    2021-01-30 10:50

    Use select_related!

    >>> user = User.objects.select_related('type1profile').get(pk=111)
    >>> user.type1profile
    None
    

提交回复
热议问题