Python Forum
Question on returning methods in a class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question on returning methods in a class
#2
Figured it out. Probably not the best approach but works.

Revised views.py
class HomeView(ListView):
    model = Board
    context_object_name = 'categories'
    template_name = 'boards/forum.html'
    queryset = Board.objects.all()


    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['subjects']=[]
        for titles in self.queryset:
            context['subjects'].append(Topic.objects.filter(board_id=titles.id))
        return context
In the html
{% for category in categories %}
    {{category}}
                    {% for titles in subjects %}
                        {% for title in titles %}
                            {% if title.board_id == category.id %}
                            <a href="#">{{title.subject}}</a><br>
                            {% endif %}
                        {% endfor %}
                    {% endfor %}
{% endfor %}
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Question on returning methods in a class - by menator01 - Feb-03-2020, 06:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Click on unusual class button using mechanize Ask Question Coto 1 3,879 Feb-18-2018, 07:27 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020