简体   繁体   English

Django filter()查询集问题

[英]django filter() queryset issue

I want to show only specific cards, related with specific post: 我只想显示与特定帖子相关的特定卡片:

UPDATE: 更新:

Current issue: 目前的问题:

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)

You can access directly your cards by doing board.cards 您可以通过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)

And then in your template: 然后在您的模板中:

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

Why access the model manager of cards? 为什么要访问卡的模型管理员? If you only want the cards for that board, try board.cards. 如果只需要该板卡,请尝试使用board.cards。 And you can filter that further 您可以进一步过滤

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM