How to fetch a boolean value from models for a specific user in Django?


I have an extended user model and I want to check it to see if the logged-in user has completed_application as per the model:

class Completed(models.Model):
class Meta:  
    verbose_name_plural = 'Completed Application'
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
completed_application = models.BooleanField(default=False)

def __str__(self):
    return f'{self.completed_application}'

def dashboard(request):
    if Completed.objects.get(completed_application = True):
        completed = True
        completed = False
    return render(request, 'dashboard.html', {'section': 'dashboard', 'completed' : completed})


{% if completed %}
<!-- You already completed an application! -->
<h1> Already completed </h1>
{% else %}
<!-- Show the application form -->
<h1> Render model form here </h1>
{% endif %}

The code above is not working for me as it returns True every time. I read quite a few posts on here but they don’t seem to be user specific such as: How to show data from django models whose boolean field is true?

>Solution :

Hi the problem is you have to change your queryset

Completed.objects.get(completed_application ...etc



Leave a ReplyCancel reply