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?