# HG changeset patch # User Brian Neal # Date 1275966588 0 # Node ID 76ad86454ce9bb4af678e9fb6b1f61ebf1428d54 # Parent cd4124b19196a94dc6d9aa0f5652142bdb3e2081 For #51, adding podcasts to Haystack search. diff -r cd4124b19196 -r 76ad86454ce9 gpp/podcast/models.py --- a/gpp/podcast/models.py Mon Jun 07 03:37:36 2010 +0000 +++ b/gpp/podcast/models.py Tue Jun 08 03:09:48 2010 +0000 @@ -3,57 +3,62 @@ from django.db import models EXPLICIT_CHOICES = ( - ('yes', 'Yes'), - ('no', 'No'), - ('clean', 'Clean'), - ) + ('yes', 'Yes'), + ('no', 'No'), + ('clean', 'Clean'), + ) class Channel(models.Model): - """Model to represent the Channel properties""" + """Model to represent the Channel properties""" - title = models.CharField(max_length=255) - link = models.URLField(verify_exists=False) - language = models.CharField(max_length=16) - copyright = models.CharField(max_length=255) - subtitle = models.CharField(max_length=255) - author = models.CharField(max_length=64) - description = models.CharField(max_length=255) - owner_name = models.CharField(max_length=64) - owner_email = models.EmailField() - image = models.ImageField(upload_to='podcast') - category = models.CharField(max_length=64) - explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) - keywords = models.CharField(max_length=255) + title = models.CharField(max_length=255) + link = models.URLField(verify_exists=False) + language = models.CharField(max_length=16) + copyright = models.CharField(max_length=255) + subtitle = models.CharField(max_length=255) + author = models.CharField(max_length=64) + description = models.CharField(max_length=255) + owner_name = models.CharField(max_length=64) + owner_email = models.EmailField() + image = models.ImageField(upload_to='podcast') + category = models.CharField(max_length=64) + explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) + keywords = models.CharField(max_length=255) - def __unicode__(self): - return self.title + def __unicode__(self): + return self.title class Item(models.Model): - """Model to represent a channel item""" - channel = models.ForeignKey(Channel) - title = models.CharField(max_length=255) - author = models.CharField(max_length=255) - subtitle = models.CharField(max_length=255) - summary = models.TextField() - enclosure_url = models.URLField(verify_exists=False) - alt_enclosure_url = models.URLField(verify_exists=False, blank=True) - enclosure_length = models.IntegerField() - enclosure_type = models.CharField(max_length=32) - guid = models.CharField(max_length=255) - pubdate = models.DateTimeField() - duration = models.CharField(max_length=16) - keywords = models.CharField(max_length=255) - explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) + """Model to represent a channel item""" + channel = models.ForeignKey(Channel) + title = models.CharField(max_length=255) + author = models.CharField(max_length=255) + subtitle = models.CharField(max_length=255) + summary = models.TextField() + enclosure_url = models.URLField(verify_exists=False) + alt_enclosure_url = models.URLField(verify_exists=False, blank=True) + enclosure_length = models.IntegerField() + enclosure_type = models.CharField(max_length=32) + guid = models.CharField(max_length=255) + pubdate = models.DateTimeField() + duration = models.CharField(max_length=16) + keywords = models.CharField(max_length=255) + explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) - @models.permalink - def get_absolute_url(self): - return ('podcast.views.detail', [str(self.id)]) + @models.permalink + def get_absolute_url(self): + return ('podcast.views.detail', [str(self.id)]) - def __unicode__(self): - return self.title + def __unicode__(self): + return self.title - class Meta: - ordering = ('-pubdate', ) + class Meta: + ordering = ('-pubdate', ) + def search_title(self): + return "%s: %s" % (self.title, self.subtitle) + + def search_summary(self): + return u"\n".join((self.subtitle, self.summary, self.keywords)) diff -r cd4124b19196 -r 76ad86454ce9 gpp/podcast/search_indexes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/podcast/search_indexes.py Tue Jun 08 03:09:48 2010 +0000 @@ -0,0 +1,13 @@ +"""Haystack search index for the news application.""" +from haystack.indexes import * +from haystack import site +from podcast.models import Item + + +class ItemIndex(SearchIndex): + text = CharField(document=True, use_template=True) + author = CharField(model_attr='author') + pub_date = DateTimeField(model_attr='pubdate') + + +site.register(Item, ItemIndex) diff -r cd4124b19196 -r 76ad86454ce9 gpp/templates/search/indexes/podcast/item_text.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/search/indexes/podcast/item_text.txt Tue Jun 08 03:09:48 2010 +0000 @@ -0,0 +1,5 @@ +{{ object.title }} +{{ object.author }} +{{ object.subtitle }} +{{ object.summary }} +{{ object.keywords }}