How to manage feeds with subclassed object in Django 1.2?

Posted by Matteo on Stack Overflow See other posts from Stack Overflow or by Matteo
Published on 2010-06-14T17:10:53Z Indexed on 2010/06/14 17:12 UTC
Read the original article Hit count: 205

Filed under:
|
|
|

Hi, I'm trying to generate a feed rss from a model like this one, selecting all the Entry objects:

from django.db import models
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from imagekit.models import ImageModel
import datetime


class Entry(ImageModel):
    date_pub = models.DateTimeField(default=datetime.datetime.now)
    author = models.ForeignKey(User)
    via = models.URLField(blank=True)
    comments_allowed = models.BooleanField(default=True)
    icon = models.ImageField(upload_to='icon/',blank=True)

    class IKOptions:
        spec_module = 'journal.icon_specs'
        cache_dir = 'icon/resized'
        image_field = 'icon'


class Post(Entry):  
    title = models.CharField(max_length=200)
    description = models.TextField()
    slug = models.SlugField(unique=True)

    def __unicode__(self):
        return self.title


class Photo(Entry):
    alt = models.CharField(max_length=200)
    description = models.TextField(blank=True)
    original = models.ImageField(upload_to='photo/')    

    class IKOptions:
        spec_module = 'journal.photo_specs'
        cache_dir = 'photo/resized'
        image_field = 'original'

    def __unicode__(self):
        return self.alt


class Quote(Entry):
    blockquote = models.TextField()
    cite = models.TextField(blank=True)

    def __unicode__(self):
        return self.blockquote

When I use the render_to_response in my views I simply call:

def get_journal_entries(request):
   entries = Entry.objects.all().order_by('-date_pub')
   return render_to_response('journal/entries.html', {'entries':entries})

And then I use a conditional template to render the right snippets of html:

{% extends "base.html" %}
{% block main %}
<hr>
{% for entry in entries %}

{% if entry.post %}[...]{% endif %}[...]

But I cannot do the same with the Feed Framework in django 1.2... Any suggestion, please?

© Stack Overflow or respective owner

Related posts about python

Related posts about django