Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
Get n items in django model using releverse relationship

Is possible to get the last n items in the Django model, using the reverse relationship.

 {% for brand in brands %}

     {% for product in brand.product_set.all %}

     {% endfor %}

{% endfor %}

I am tried in this way, But it prints all things. But want only last 3 items

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can make use of the |slice template tag [Django-doc] to slice the collection with:

{% for brand in brands %}
    {% for product in brand.product_set.reverse|slice:":3" %}
        …
    {% endfor %}
{% endfor %}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda