简体   繁体   中英

How to compare value of 2 fields in Django QuerySet?

I have a django model like this:

class Player(models.Model):
    name = models.CharField()
    batting = models.IntegerField()
    bowling = models.IntegerField()

What would be the Django QuerySet equivalent of the following SQL?

SELECT * FROM player WHERE batting > bowling;

In django 1.1 you can do the following:

players = Player.objects.filter(batting__gt=F('bowling'))

See the other question for details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM