I'm putting together a basic feed aggregator with the following
classes in my app's model: category, feed and feeditem. Each feed is
tied to a category (ForeignKey), and each feeditem is tied to a Feed
(ForeignKey).
Here is my model:
------------
from django.db import models
class Category(models.Model):
slug = models.SlugField(prepopulate_from=('title',), help_text='This
field will prepopulate from the title field.', unique=True)
title = models.CharField(max_length=50)
description = models.TextField(help_text='A brief summary of this
category.')
class Admin:
list_display = ('slug', 'title')
class Meta:
verbose_name_plural = 'categories'
def __unicode__(self):
return self.title
def get_feeds(self):
"""
Returns the feed object for the category.
"""
return Feed.objects.filter(category=self)
def get_absolute_url(self):
return '/category/%s/' % (self.slug)
class Feed(models.Model):
title = models.CharField(max_length=200, help_text='The name of
the site providing the feed.')
feed_url = models.URLField(unique=True, help_text='The feed URL.')
public_url = models.URLField(help_text='The URL of the site
providing the feed.')
is_defunct = models.BooleanField()
category = models.ForeignKey(Category)
class Meta:
db_table = 'aggregator_feeds'
class Admin:
list_filter = ('category',)
def __unicode__(self):
return self.title
def get_feeditems(self):
"""
Returns the feeditem object for the feed.
"""
return FeedItem.objects.filter(feed=self)
def get_absolute_url(self):
return self.feed_url
class FeedItem(models.Model):
feed = models.ForeignKey(Feed)
title = models.CharField(max_length=200)
link = models.URLField()
summary = models.TextField(blank=True)
date_modified = models.DateTimeField()
guid = models.CharField(max_length=200, unique=True,
db_index=True)
class Meta:
db_table = 'aggregator_feeditems'
ordering = ("-date_modified",)
def __unicode__(self):
return self.title
def get_absolute_url(self):
return self.link
----------
I want to be able to display the FeedItems for a given category. What
would be the best way to approach this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---