How to convert this query to a "django model query" ?

Posted by fabriciols on Stack Overflow See other posts from Stack Overflow or by fabriciols
Published on 2010-03-28T17:46:11Z Indexed on 2010/03/28 17:53 UTC
Read the original article Hit count: 668

Filed under:
|
|

Hello !

What i want is simple :

models :


class userLastTrophy(models.Model):
   user     = models.ForeignKey(userInfo)
   platinum = models.IntegerField()
   gold    = models.IntegerField()
   silver  = models.IntegerField()
   bronze  = models.IntegerField()
   level   = models.IntegerField()
   rank    = models.IntegerField()
   perc_level = models.IntegerField()
   date_update = models.DateTimeField(default=datetime.now, blank=True)
   total   = models.IntegerField()
   points  = models.IntegerField()

class userTrophy(models.Model):
   user     = models.ForeignKey(userInfo)
   platinum = models.IntegerField()
   gold    = models.IntegerField()
   silver  = models.IntegerField()
   bronze  = models.IntegerField()
   total   = models.IntegerField()
   level   = models.IntegerField()
   perc_level  = models.IntegerField()
   date_update = models.DateTimeField(default=datetime.now, blank=True)
   rank    = models.IntegerField(default=0)
   total   = models.IntegerField(default=0)
   points  = models.IntegerField(default=0)
   last_trophy = models.ForeignKey(userLastTrophy, default=0)

I have this query :


select t2.user_id as id,
       t2.platinum - t1.platinum as plat,
       t2.gold     - t1.gold as gold,
       t2.silver   - t1.silver as silver,
       t2.bronze   - t1.bronze as bronze,
       t2.points   - t1.points as points from myps3t_usertrophy t2, myps3t_userlasttrophy t1 where
       t1.id = t2.last_trophy_id order by points;

how to do this with django models ?

© Stack Overflow or respective owner

Related posts about django

Related posts about models