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.dispatch import dispatcher
from django.contrib.sites.models import Site
from django.contrib.sites.managers import CurrentSiteManager
from publish.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)

            pub_date = instance.publish
            site = instance.site

            if instance.status == 1:
                create = False

            if create:
                ti =
TumbleItem.objects.get_or_create(content_type=ctype,
object_id=instance.id, pub_date=pub_date, site=site)

# 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)

Basically I'm getting an error that I can't pass site=site on the post
which is a ManyToManyField.  I'm trying to make this tumblelog work
across a dozen sites.  Any ideas?

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to