Django3: How to render HTML template based on tuple choice

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.filter(limitation=['help','invest,'mc']
    template = 'blog/blog.html'
    context = {'blog': blog}
    return render(request, template, context)

then the hmtl template

        {% for blog in blog%}
            {% if blog.limitation['help'] %}**
            <div class="col-lg-4 col-md-6">
              <div class="help-wrap">
                <img src="{{blog.featured}}" class="img-fluid" alt="">
                <div class="blog-info">
                  <h4>{{blog.title}}</h4>
                  <p></p>
                  <div class="help-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 %}  

            {% if blog.limitation['invest'] %}**
            <div class="col-lg-4 col-md-6">
              <div class="invest-wrap">
                <img src="{{blog.featured}}" class="img-fluid" alt="">
                <div class="blog-info">
                  <h4>{{blog.title}}</h4>
                  <p></p>
                  <div class="invest-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 %}

            {% if blog.limitation['mc'] %}**
            <div class="col-lg-4 col-md-6">
              <div class="mc-wrap">
                <img src="{{blog.featured}}" class="img-fluid" alt="">
                <div class="blog-info">
                  <h4>{{blog.title}}</h4>
                  <p></p>
                  <div class="mc-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 the particular limitation as the chosen choice please how can I achieve this?
I am using django3

NOTE: I have updated the query based on @KenWhitesell 's instruction after testing it I now put all the expected limitations in the list so that output will be shown for each tab based on the particular limitation.

The error I am getting is: Could not parse the remainder: ‘[‘AI’]’ from ‘portfolio.limitation[‘AI’]’
please how can I retrieve data strictly based on a particular limitation’s choice.

This type of filtering isn’t done in the templates, it’s supposed to be done in the views.

# Note - the line above this is ``` - notice how the formatting is maintained?
def view_portfolio(request):
    blog= Blog.objects.filter(limitation='**help**')
    template = 'blog/blog.html'
    context = {'blog': blog}
    return render(request, template, context)
# Note - the line after this is ```

See: Retrieving specific objects with filters.

Thank you so much @KenWhitesell for your reply, unfortunately this didn’t show any output in my template and I have actually updated the question to generalize it, since what really happen is that I have 3 tabs that per each tab content is expected to show based on the particular limitation (maybe help,invest,mc). I will really be grateful for your assistance in solving this

What did you define as your filter?

(As written, what you wrote doesn’t make sense to me. You’re generating three different lists, one per tab - that should be three different querysets being generated, one per tab.)

OK thank you very much @KenWhitesell this is now how I defined it:

def view_portfolio(request):
    blog= Blog.objects.all()

    help_help = Blog.objects.filter(

        limitation='help')[:12]

    invest_blog = Blog.objects.filter(

        limitation='invest')[:12]

    mc_blog = Blog.objects.filter(

        limitation='mc')[:12]

    content = {

        'blog': blog,

        'invest_blog': invest_blog,

        'mc_blog': mc_blog,

        'help_blog': help_blog,

    }

    templates = 'index.html'

    return render(request, templates, content)

Then in the HTML template I did something like:

{% for port in blog %}

         

          <div class="col-lg-4 col-md-6 portfolio-item filter-app">

              <div class="portfolio-wrap">

                <img src="{{mc_blog.featured.url}}" class="img-fluid" alt="">

                <div class="portfolio-info">

                  <h4>{{mc_blog.title}}</h4>

                  <p></p>

                  <div class="portfolio-links">

                    <a href="{{mc_blog.featured.url}}" data-gall="portfolioGallery" class="venobox" title="{{aiport.title}}"><i class="bx bx-plus"></i></a>

                    <a href="portfolio-details.html" title="More Details"><i class="bx bx-link"></i></a>

                  </div>

                </div>

              </div>

            </div>

            

          <div class="col-lg-4 col-md-6 portfolio-item filter-web">

            <div class="portfolio-wrap">

              <img src="{{help.featured.url}}" class="img-fluid" alt="">

              <div class="portfolio-info">

                <h4>{{help_blog.title}}</h4>

                <p>{{help_blog.title}}</p>

                <div class="portfolio-links">

                  <a href="{{help_blog.featured.url}}" data-gall="portfolioGallery" class="venobox" title="{{help_blog.title}}"><i class="bx bx-plus"></i></a>

                  <a href="portfolio-details.html" title="More Details"><i class="bx bx-link"></i></a>

                </div>

              </div>

            </div>

          </div>

          <div class="col-lg-4 col-md-6 portfolio-item filter-card">

            <div class="portfolio-wrap">

              <img src="{{invest_blog.featured.url}}" class="img-fluid" alt="">

              <div class="portfolio-info">

                <h4>{{invest_blog.title}}</h4>

                <p>{{invest_blog.title}}</p>

                <div class="portfolio-links">

                  <a href="{{invest_blog.featured.url}}" data-gall="portfolioGallery" class="venobox" title="{{invest_blog.title}}"><i class="bx bx-plus"></i></a>

                  <a href="portfolio-details.html" title="More Details"><i class="bx bx-link"></i></a>

                </div>

              </div>

            </div>

          </div>

        {% endfor %}

I am really grateful for your time @KenWhitesell , I know it isn’t easy to help someone fix a problem in this busy world.

So this is how I tried to fix this based on the .filter guide you told me earlier.

So you’re really close. Since you’ve got your lists as individual entries in content, there’s no need to pass blog into the template.

Then within your template:

# HTML wrapper for tab goes here
{% for blog in invest_blog %}
# Render each blog here
# End of tab

# HTML wrapper for tab goes here
{% for blog in mc_blog %}
# Render each blog here
# End of tab

# HTML wrapper for tab goes here
{% for blog in help_blog %}
# Render each blog here
# End of tab

Wow!!! thank you very much for your guide and working solution, I really appreciate you sir.