Feb-03-2020, 04:17 PM
As the title states, I'm trying to figure out how to access the return on a query in django.
models.py
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
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts