title: Custom function to query database across Django views
body: <p>In 'myapp' I have a model 'Profile', which shares a OnetoOneField relationship with my custom User model. In many of my views, I need to check if the user has a profile set up. So I have created a module 'profilecheck' which contains this function:</p>
  
  <pre><code>def has_profile(req):
      try:       
          profile = Profile.objects.get(user=req.user)
          return profile
      except: 
          return False
  </code></pre>
  
  <p>In my views.py, I have the following:</p>
  
  <pre><code>from myapp.utils.profilecheck import has_profile
  from myapp.models import Profile
  
  def viewprofile(request):   
      if has_profile(request):
          context = {
              'profile': has_profile(request) 
          }
          return render(request, 'profile.html', context)         
      else:
          return render(request, 'setup_profile.html', {})
  </code></pre>
  
  <p>When called in the view, has_profile() always returns False. Any ideas why?</p>