Hi,

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

Change that as follows:

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

Also, it's common practice to pluralize the names of your
ManyToManyFields...so in the above case it would be 'sites' instead of
'site'.

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