python - Model inheritance and RSS Feed framework -
I am using model succession to manage a model:
Import the DB import model from Django Django.contrib.sites.models from django.contrib.auth.models Import the site from imagekit.models to import the user image imported datetime class entry (models.Model): date_pub = models.DateTimeField (default) = Datetime.datetime () = Model. URLField (blank = true) comments_allowed = models.BooleanField (default = true) class IKOptions: spec_module = 'journal.icon_specs' cache_dir = 'icon / resized' image_field =) via author = Models.For EignKey (user) 'icon' class post (entry): title = model.carfield (max_long = 200) description = model. TextField () Slug = Model. Slufffield (Exclusive = True) Def __unicode __ (self): Returns Self Title class photo (Entry): Alt = models.CharField (max_length = 200) Description = models.TextField (empty = true) Original = Model ImageField (upload_to = 'Photo /') def __unicode __ (self): return self class class coat (entry): blockquote = model. TextField () Quote = Model. TextField (empty = true) def __unicode __ (self): Returns the self
A conditional template Entry.objects With a view based on all () :
is enough to render the right snippet of html {% "base.html"%} {% Block main%} & lt; Hr & gt; {%} To enter entries {% entry.post%}, or something with [entry.post] {% endif%} {% Insert.photo%} [...] Do something with the entry. Photo] {% Endif%} [... and similarly]
Now I am trying to use the new feed framework that generates an RSS feed, but no luck without. The more-simplified settings of the structure do not specify the conditional item_title and item_description based on the entry of child objects:
Django.contrib Import totanus.journal.models from import .syndication.views entry, photo, post, quote class latest entredged feed (feed): title = "RSS feed" link = "/ journal /" description = "journal RSS" def item ): Return Entry.objects.order_by ('- date_pub') [: 10] def item_title (auto, item): # if kid post retire No item. Post.title # This is not working, of course ...
Should I manage a custom view-template set that is to create RSS and syndication or this sub- Is there a way to use feed structures with classified models?
You have two options:
-
on the feed class Use the
title_template
anddescription_template
attributes, which indicate templates that can handle a lot of generic input variables. -
Re-create your template logic in the feed class ways so that your template variable can get a generalized piece of data.
Either one will take you to the same end point.
Comments
Post a Comment