views:

570

answers:

1

In first version we can use custom table for ManyToManyField with parameter through=MyModel. MyModel should include foreign keys. But I want to use generic foreign key:

content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')

content object as foreign key.

How can I do it?

A: 

I think your best bet here is to use your own intermediary table/model, with its own generic foreign keys and either writing a custom manager or method to retrieve the information you want. The current implementation of ManyToManyField doesn't have this functionality, and you'll probably struggle to get it to work as such.

Definately should file a ticket if there isn't one there already to see what the django developers think should be done regarding this situation though. :)

Mike Scott