tags:

views:

36

answers:

1

Hi, I have a generic foreign key in one of my models:

# models.py  
class Tasks(models.Model):  
    content_type = models.ForeignKey(ContentType, limit_choices_to=tasktype_limits, null=True, blank=True)  
    object_id = models.PositiveIntegerField(null=True, blank=True, )  
    target = generic.GenericForeignKey('content_type', 'object_id')  
    ttype = models.ForeignKey('TaskType')  
    status = models.CharField(max_length = 60, null=False, blank=False)  
    comments = models.TextField(null=True, blank=True, )  

Now I'd like to fetch all the tasks and it's "targets" with AJAX:

# views.py  
def get_tasks(request, task_id):  
    tasks = Tasks.objects.all()  
    return HttpResponse(serializers.serialize('json', tasks))`

The Ajax-Call is working so far, but it doesn't return the objects related to the target-field. How can I do that?

A: 

Not sure if this is related, but there was a bug reported about the serialization of contenttypes (#7052; see related discussion). I believe it was fixed in Django 1.2. Which version of Django are you using?

Manoj Govindan
I'm using Django 1.2.1