I am blanking out on this as I have no experience to draw upon to be able to come up with a solution.
That’s what my model looks like:
class Category(models.Model):
category = models.CharField(max_length=50)
class News(models.Model):
headline = models.CharField(max_length=100)
category = models.ForeignKey(Category)
I am passing to my template a news object.
What I want the template to do is to loop through this news object, and display an html page that looks like this:
Category 1
headline 1
headline 2
...
Category 2
headline 1
headline 2
headline 3
...
Category ....
And so on for every category in the news object that I passed to the template.
As an example, a category can be ‘world news’, ‘sports’ …
and the headline will be anything that is related to that category
thanks in advance for any help!!
You want to regroup the news queryset by category.