开发者

In Django I have a complex query where I need only the unique values through a foreign key, is this possible?

开发者 https://www.devze.com 2023-01-08 10:40 出处:网络
I have the following models: class Indicator(models.Model): name = models.CharField(max_length=200) category = models.ForeignKey(IndicatorCategory)

I have the following models:

class Indicator(models.Model):
    name = models.CharField(max_length=200)
    category = models.ForeignKey(IndicatorCategory)
    weight = models.IntegerField()
    industry = models.ForeignKey(Industry)

    def __unicode__(self):
        return self.name
    class Meta:
        ordering = ('name',)

class IndicatorRatingOption(models.Model):
    indicator = models.ForeignKey(Indicator)
    description = models.TextField()
    value = models.FloatField(null=True)

    def __unicode__(self):
        return self.description

class Rating(models.Model):
    product = models.ForeignKey(Product, null=True)
    company = models.ForeignKey(Company, null=True)
    rating_option = models.ForeignKey(开发者_如何学CIndicatorRatingOption)
    value = models.IntegerField(null=True)

What I need to do is get all of the company rating options of two companies without having them overlap on their Indicators (rating.rating_option.indicator). If there's a conflict, company 'a' would always win over company 'b'. How do I do this?


This works:

Rating.objects.filter(company__in=[company_a, company_b]).distinct()

(Original answer)

Did you try

IndicatorRatingOptions.objects.filter(company__in=[company_a, company_b]).distinct()

?

0

精彩评论

暂无评论...
验证码 换一张
取 消