How to convert this query to a "django model query" ?
- by fabriciols
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 ?