django filter()queryset问题

时间:2017-09-06 20:29:25

标签: python django

我只想显示与特定帖子相关的特定卡片:

更新:

当前问题:

Internal Server Error: /board/table/card/create/
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\django\core\handlers\excepti
on.py", line 41, in inner
    response = get_response(request)

2 个答案:

答案 0 :(得分:0)

您可以通过board.cards

直接访问您的卡片
def board_detail(request, slug):
    board = get_object_or_404(Board, title=slug)
    cards = board.cards
    # ___________^

    template = 'board/board_detail.html'
    context = {'board': board, 'cards': cards}

    return render(request, template, context)

然后在你的模板中:

{% for card in cards %}
    <p>{{ card.title_card }}</p>
{% endfor %}

答案 1 :(得分:0)

为什么要访问卡的模型管理器?如果您只想要该卡的卡,请尝试board.cards。你可以进一步过滤