views:

23

answers:

0

I have the following problem. I have these 3 models

class Model1(models.Model):
    name = models.CharField()

class Model2(models.Model):
     user = models.ForeignKey(User)
     parent = models.ForeignKey(Model1)

class Model3(models.Model):
     user = models.ForeignKey(User)
     content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
     object_id = models.PositiveIntegerField(_('object id'), db_index=True)
     object = generic.GenericForeignKey('content_type', 'object_id')

I have a query which returns all objects in model 1. Next I want to sort these objects on the sum of objects model2 and model3 for the current user. Model3 is connected to model1 through the content_type. What is the best solution for this?