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
#1
As the title states, I'm trying to figure out how to access the return on a query in django.

models.py
class Board(models.Model):
    category = models.CharField(max_length=20, unique=True)
    description = models.CharField(max_length=100)

    def __str__(self):
        return self.category


class Topic(models.Model):
    subject = models.CharField(max_length=100, unique=True)
    board = models.ForeignKey(Board, on_delete=models.CASCADE)
views.py
class HomeView(ListView):
    model = Board
    context_object_name = 'categories'
    template_name = 'boards/forum.html'
    queryset = Board.objects.all()
    titles=queryset

    def get_category_subjects(self):

        for title in self.titles:
            subjects = Topic.objects.filter(board_id=title.id)
        return subjects
for category in categories:
    print(category)
    for title in category.get_category_subjects:
        print(title)
Any help would be great. Thanks.
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
Question on returning methods in a class - by menator01 - Feb-03-2020, 04:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Click on unusual class button using mechanize Ask Question Coto 1 3,810 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