I'd like to display all available feeds on one page, but I don't want to hard code each feed. Something like sending in a queryset of feeds would be perfect, like:
{% for feed in feeds %} {{ feed.link }} {{ feed.name }} {{ feed.description }} {% endfor %}
From what I understand, Feeds in the Django Syndication Framework are created as individual classes that inherit from class (feed). This means I can't create a queryset for all feeds, only for individual feeds.
How can I send in a queryset of feeds, if they are each a different class? Is this only possible by way of crafting a queryset from a class that references each feed using generic foreignkey relations? Or can I actually send in a queryset of the parent [feed] class?
Bonus question: is there a simple way to aggregate a "full-feed" from all individual feeds?
Many thanks!
If you can enumerate feeds in advance you can create a list of feeds and put it into the template...
feeds = [feed_a,feed_b,...]
feeds.append(feed_c)
...
I've tried an approach below and it did not work , which actually could be made to work since "related_name" only creates an accessor function and does not affect DB tables.
#this code does not work in Django v1
class FeedCollection(models.Model):
subject = models.CharField(max_length=256)
class BloggerFeed(models.Model):
collection = models.ForeignKey(FeedCollection,related_name='feed')
class CNNFeed(models.Model):
collection = models.ForeignKey(FeedCollection,related_name='feed')
Django complains that accessor functions FeedCollection.feed_set
for the two feed tables clash.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.