pythondjangodjango-viewsdjango-templates

How to show data from django models whose boolean field is true?


verified = models.BooleanField(default=False)

I want to show only that objects in frontend whose verified field is true in Django models.


Solution

  • There are many ways

    1. you can handle this on your views

    in views.py

    modelList = modelname.objects.filter(verified=True)
    
    1. also you can handle it on HTML

    in views.py

    modelList = modelname.objects.all()
    

    in html

    {% for models in modelList %}
    
        {% if models.verified == True %}
           # Your Code
        {% endif %}
    
    {% endfor %}