I have a bunch of objects of Model A (which really aren't important..), and i have a model B, located in another app.

Model B refers to other objects as such:

content_object  = generic.GenericForeignKey('content_type', 'object_id')

I'm only interested in the objects that hold references to types of Model A. Would it be possible to (somehow) use the template 'backwards'-functionality to retrieve them?

i've tried:

 {% for a in objectA.objectB_set.all %}
 and so on..

But it doesn't seem to work with 'generics'..?

有帮助吗?

解决方案

It's not a real relationship, so objectA doesn't know anything about the B objects. You need to define a GenericRelation to ModelA to point back to B.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top