I've been setting trying to set up a tumblelog using the sites framework and the current site manager and I'm hitting a bug in either my code or Django's not sure which.
Basically what's happening is the first time I save an object the tumble item is created, but the site field is not populated so it will not show up on any site. The second time I save an object the site field is then populated and the tumble item shows up on the appropriate site. I'm not sure what's going on here, but it's driving me nuts. Any ideas? from django.db import models from django.contrib.contenttypes import generic from django.template.loader import render_to_string from django.db.models import signals from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.contrib.sites.managers import CurrentSiteManager from posts.models import * class TumbleItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() pub_date = models.DateTimeField() site = models.ManyToManyField(Site) objects = models.Manager() on_site = CurrentSiteManager() content_object = generic.GenericForeignKey('content_type', 'object_id') def get_rendered_html(self): template_name = 'tumblelog/includes/tumble_item_%s.html' % (self.content_type.name) return render_to_string(template_name, { 'object': self.content_object }) def create_tumble_item(sender, instance, signal, *args, **kwargs): # Check to see if the object was just created for the first time if 'created' in kwargs: if kwargs['created']: create = True # Get the instance's content type ctype = ContentType.objects.get_for_model(instance) site = instance.site pub_date = instance.publish if instance.status == 1: create = False if create: ti, created = TumbleItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date) for s in site.all(): ti.site.add(s) else: create = True # Get the instance's content type ctype = ContentType.objects.get_for_model(instance) pub_date = instance.publish site = instance.site if instance.status == 1: create = False if create: ti, created = TumbleItem.objects.get_or_create(content_type=ctype, object_id=instance.id, pub_date=pub_date) for s in site.all(): ti.site.add(s) # Send a signal on post_save for each of these models for Post in [Article, Audio, Video, Download, Quote, Photo, Link, Snippet]: models.signals.post_save.connect(create_tumble_item, sender=Post) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---