I have created a model, views and templates like so:
MODEL
project_choices = (
('Speaker', (
('help', 'Freedom'),
)),
('Money', (
('invest', 'Investment'),
)
),
(
'Children', (
('mc', 'Mother & Child'),
)
),
)
class Blog(models.Model):
title = models.CharField(max_length=250)
description = CKEditor5Field('Text', null=True)
limitation = models.CharField(
null=True, max_length=50, choices=project_choices)
def __str__(self):
return self.title
Now the VIEW
def view_portfolio(request):
blog= Blog.objects.all()
template = 'blog/blog.html'
context = {'blog': blog}
return render(request, template, context)
then the hmtl template
{% for blog in blog%}
{% if blog.limitation['**help**'] %}**//I have also tried {% if portfolio.limitation == project_choices['AI']%}**
<div class="col-lg-4 col-md-6">
<div class="portfolio-wrap">
<img src="{{blog.featured}}" class="img-fluid" alt="">
<div class="blog-info">
<h4>{{blog.title}}</h4>
<p></p>
<div class="portfolio-links">
<a href="{{blog.featured}}" data-gall="blogGallery" class="venobox" title="{{blog.title}}"><i class="bx bx-plus"></i></a>
<a href="blog-details.html" title="More Details"><i class="bx bx-link"></i></a>
</div>
</div>
</div>
</div>
{% endif %}
{%endfor%}
My goal is to show blogs based on ONLY help as the chosen choice please how can I achieve this?
I am using django3
question from:
https://stackoverflow.com/questions/65651083/django-how-to-render-html-template-based-on-tuple-choice 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…