Django 比较相同模型的字段

Django 比较相同模型的字段,django,mongodb,orm,Django,Mongodb,Orm,我有这个模型: #Model for match result forecast class ResultForecast(models.Model): user = models.ForeignKey(User) created_date = models.DateTimeField('match date', blank=True, null=True) home_goals = models.DecimalField(max_digits=5, decimal_pl

我有这个模型:

#Model for match result forecast
class ResultForecast(models.Model):
    user = models.ForeignKey(User)
    created_date = models.DateTimeField('match date', blank=True, null=True)
    home_goals = models.DecimalField(max_digits=5, decimal_places=0, blank=True, null=True)
    away_goals = models.DecimalField(max_digits=5, decimal_places=0, blank=True, null=True)
    match = models.ForeignKey(Match, related_name='forecasted_match')
所以我想得到主场目标大于客场目标的物体,反之亦然,我用这个:

total_forecast = ResultForecast.objects.filter(match=match).count()
home_trend =  ResultForecast.objects.filter(match=match, home_goals__gt=F('away_goals'))
away_trend = ResultForecast.objects.filter(match=match, away_goals__gt=F('home_goals')) 

但它不起作用

我想知道匹配是否应该是精确匹配?您是否尝试过以下方法,看看是否有什么不同?我也更喜欢使用Q类

from django.db.models import Q

    home_trend =  ResultForecast.objects.filter(
        Q(match__exact=match) & 
        Q(home_goals__gt=F('away_goals')))

    away_trend = ResultForecast.objects.filter(
        Q(match__exact=match) & 
        Q(away_goals__gt=F('home_goals')))