Reputation: 1
verified = models.BooleanField(default=False)
I want to show only that objects in frontend whose verified field is true in Django models.
Upvotes: 0
Views: 1255
Reputation: 66
There are many ways
in views.py
modelList = modelname.objects.filter(verified=True)
in views.py
modelList = modelname.objects.all()
in html
{% for models in modelList %}
{% if models.verified == True %}
# Your Code
{% endif %}
{% endfor %}
Upvotes: 1
Reputation: 790
you have to ways to achive that that either it with your views or html
first views you can filter your model to return only object which is verfied like this
name = modelname.objects.filter(verified=True)
second way or you can pass in html while you are requesting all object of that field in views in views
name = modelname.objects.all()
then in html while fetching data
{% for name in models %}
{% if name.verified == True %}
then pass the object which are verified
{% else %}
pass another data
{% endif %}
{% endfor %}
i hope now you got my point tell me if you got any error while implementing any of these code
Upvotes: 0
Reputation: 477814
You filter the items with:
MyModel.objects.filter(verified=True)
with MyModel
the model that contains the verified
field.
Upvotes: 0