Show in a tab the content of a [closed] model

1

Good I am trying to show the content of a model in a template, the problem is the following one: I do not know how to do to show the content depending on the option to which you click. Since I am using a for in the template, only the content of the last record in the table is shown, if someone can help me or suggest what I can do.

My model:

class Beneficio(models.Model):
    OP_DEP = (
        ('Afiliacion', 'Afiliacion'),
        ('Bienestar y Seguridad Social', 'Bienestar y Seguridad Social'),
        ('Beneficios del Trabajador', 'Beneficios del Trabajador'),
        ('Créditos', 'Créditos'),
        ('SISA', 'SISA'),
        ('Inversora', 'Inversora'),
    )
    autor = models.ForeignKey('auth.User')
    dependencia = models.CharField(
        max_length=100,
        choices=OP_DEP,
        default='AA'
    )
    beneficio = models.CharField(max_length=100, unique=True)
    texto = HTMLField('Texto')
    fecha_creacion = models.DateTimeField(default=timezone.now)
    fecha_publicacion = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return self.dependencia

My views:

def bafiliacion(request):
    afi = Beneficio.objects.filter(fecha_publicacion__lte=timezone.now())

    return render(request, 'noticias/beneafiliacion.html', {'afi': afi})

My template:

    <div class="Beneficios">

    <div class="container-fluid">
    <div class="col-md-4">
            <ul class="nav nav-tabs tabs-left">
            {% for item in afi  %}    
            <li><a href="#{{item.beneficio}}" data-toggle="tab">                    {{item.beneficio}}</a></li>
            {% endfor %}     
            </ul>    
            </div>
            <div class="col-md-8">
                <div class="tab-content">
                {% for item in afi %}                                            
                    <div class="tab-pane" id="{{item.beneficio}}">{{item.texto|safe}}</div>
                {% endfor %}    
                </div>
            </div>

This is an image of what is supposed to show me

If I click on the option that says survivor it shows me the text that it would show, but when clicking on the other two options it does not show me anything in the respective tab

    
asked by Hitokirilv4 31.01.2017 в 15:27
source

0 answers