0
以下是我正在嘗試做的事情。
當然,這會很慢,並想知道是否有更好的方法來做到這一點。Django。得到相關查詢集的聯合
class Foo(models.Model):
bars = generic.GenericRelation(Bar)
class Meta:
abstract = True
class Bar(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
invitation = generic.GenericForeignKey('content_type', 'object_id')
timestamp = models.DateTimeField(auto_now_add=True, db_index=True)
meat = models.ForeignKey(Jessy)
bars = Bar.objects.none()
for foo in Foo.objects.all():
bars = bars | Q(foo.bars.all())
bars.values('meat').order_by('timestamp'):